diff options
Diffstat (limited to 'contrib/gcc')
-rw-r--r-- | contrib/gcc/choose-temp.c | 74 | ||||
-rw-r--r-- | contrib/gcc/config/alpha/alpha.c | 10308 | ||||
-rw-r--r-- | contrib/gcc/config/alpha/elf.h | 459 | ||||
-rw-r--r-- | contrib/gcc/config/alpha/freebsd.h | 133 | ||||
-rw-r--r-- | contrib/gcc/cppinit.c | 634 | ||||
-rw-r--r-- | contrib/gcc/dwarfout.c | 6561 | ||||
-rw-r--r-- | contrib/gcc/f/g77spec.c | 568 | ||||
-rw-r--r-- | contrib/gcc/make-temp-file.c | 181 | ||||
-rw-r--r-- | contrib/gcc/pexecute.c | 794 |
9 files changed, 0 insertions, 19712 deletions
diff --git a/contrib/gcc/choose-temp.c b/contrib/gcc/choose-temp.c deleted file mode 100644 index 7f33f83..0000000 --- a/contrib/gcc/choose-temp.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Utility to pick a temporary filename prefix. - Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. - -This file is part of the libiberty library. -Libiberty is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -Libiberty is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If not, -write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> /* May get P_tmpdir. */ -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif - -#include "libiberty.h" -extern char *choose_tmpdir PARAMS ((void)); - -/* Name of temporary file. - mktemp requires 6 trailing X's. */ -#define TEMP_FILE "ccXXXXXX" -#define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1) - -/* - -@deftypefn Extension char* choose_temp_base (void) - -Return a prefix for temporary file names or @code{NULL} if unable to -find one. The current directory is chosen if all else fails so the -program is exited if a temporary directory can't be found (@code{mktemp} -fails). The buffer for the result is obtained with @code{xmalloc}. - -This function is provided for backwards compatability only. Its use is -not recommended. - -@end deftypefn - -*/ - -char * -choose_temp_base () -{ - const char *base = choose_tmpdir (); - char *temp_filename; - int len; - - len = strlen (base); - temp_filename = xmalloc (len + TEMP_FILE_LEN + 1); - strcpy (temp_filename, base); - strcpy (temp_filename + len, TEMP_FILE); - - mktemp (temp_filename); - if (strlen (temp_filename) == 0) - abort (); - return temp_filename; -} diff --git a/contrib/gcc/config/alpha/alpha.c b/contrib/gcc/config/alpha/alpha.c deleted file mode 100644 index f9aef99..0000000 --- a/contrib/gcc/config/alpha/alpha.c +++ /dev/null @@ -1,10308 +0,0 @@ -/* Subroutines used for code generation on the DEC Alpha. - Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - - -#include "config.h" -#include "system.h" -#include "coretypes.h" -#include "tm.h" -#include "rtl.h" -#include "tree.h" -#include "regs.h" -#include "hard-reg-set.h" -#include "real.h" -#include "insn-config.h" -#include "conditions.h" -#include "output.h" -#include "insn-attr.h" -#include "flags.h" -#include "recog.h" -#include "expr.h" -#include "optabs.h" -#include "reload.h" -#include "obstack.h" -#include "except.h" -#include "function.h" -#include "toplev.h" -#include "ggc.h" -#include "integrate.h" -#include "tm_p.h" -#include "target.h" -#include "target-def.h" -#include "debug.h" -#include "langhooks.h" -#include <splay-tree.h> -#include "cfglayout.h" - -/* Specify which cpu to schedule for. */ - -enum processor_type alpha_cpu; -static const char * const alpha_cpu_name[] = -{ - "ev4", "ev5", "ev6" -}; - -/* Specify how accurate floating-point traps need to be. */ - -enum alpha_trap_precision alpha_tp; - -/* Specify the floating-point rounding mode. */ - -enum alpha_fp_rounding_mode alpha_fprm; - -/* Specify which things cause traps. */ - -enum alpha_fp_trap_mode alpha_fptm; - -/* Specify bit size of immediate TLS offsets. */ - -int alpha_tls_size = 32; - -/* Strings decoded into the above options. */ - -const char *alpha_cpu_string; /* -mcpu= */ -const char *alpha_tune_string; /* -mtune= */ -const char *alpha_tp_string; /* -mtrap-precision=[p|s|i] */ -const char *alpha_fprm_string; /* -mfp-rounding-mode=[n|m|c|d] */ -const char *alpha_fptm_string; /* -mfp-trap-mode=[n|u|su|sui] */ -const char *alpha_mlat_string; /* -mmemory-latency= */ -const char *alpha_tls_size_string; /* -mtls-size=[16|32|64] */ - -/* Save information from a "cmpxx" operation until the branch or scc is - emitted. */ - -struct alpha_compare alpha_compare; - -/* Nonzero if inside of a function, because the Alpha asm can't - handle .files inside of functions. */ - -static int inside_function = FALSE; - -/* The number of cycles of latency we should assume on memory reads. */ - -int alpha_memory_latency = 3; - -/* Whether the function needs the GP. */ - -static int alpha_function_needs_gp; - -/* The alias set for prologue/epilogue register save/restore. */ - -static GTY(()) int alpha_sr_alias_set; - -/* The assembler name of the current function. */ - -static const char *alpha_fnname; - -/* The next explicit relocation sequence number. */ -extern GTY(()) int alpha_next_sequence_number; -int alpha_next_sequence_number = 1; - -/* The literal and gpdisp sequence numbers for this insn, as printed - by %# and %* respectively. */ -extern GTY(()) int alpha_this_literal_sequence_number; -extern GTY(()) int alpha_this_gpdisp_sequence_number; -int alpha_this_literal_sequence_number; -int alpha_this_gpdisp_sequence_number; - -/* Costs of various operations on the different architectures. */ - -struct alpha_rtx_cost_data -{ - unsigned char fp_add; - unsigned char fp_mult; - unsigned char fp_div_sf; - unsigned char fp_div_df; - unsigned char int_mult_si; - unsigned char int_mult_di; - unsigned char int_shift; - unsigned char int_cmov; -}; - -static struct alpha_rtx_cost_data const alpha_rtx_cost_data[PROCESSOR_MAX] = -{ - { /* EV4 */ - COSTS_N_INSNS (6), /* fp_add */ - COSTS_N_INSNS (6), /* fp_mult */ - COSTS_N_INSNS (34), /* fp_div_sf */ - COSTS_N_INSNS (63), /* fp_div_df */ - COSTS_N_INSNS (23), /* int_mult_si */ - COSTS_N_INSNS (23), /* int_mult_di */ - COSTS_N_INSNS (2), /* int_shift */ - COSTS_N_INSNS (2), /* int_cmov */ - }, - { /* EV5 */ - COSTS_N_INSNS (4), /* fp_add */ - COSTS_N_INSNS (4), /* fp_mult */ - COSTS_N_INSNS (15), /* fp_div_sf */ - COSTS_N_INSNS (22), /* fp_div_df */ - COSTS_N_INSNS (8), /* int_mult_si */ - COSTS_N_INSNS (12), /* int_mult_di */ - COSTS_N_INSNS (1) + 1, /* int_shift */ - COSTS_N_INSNS (1), /* int_cmov */ - }, - { /* EV6 */ - COSTS_N_INSNS (4), /* fp_add */ - COSTS_N_INSNS (4), /* fp_mult */ - COSTS_N_INSNS (12), /* fp_div_sf */ - COSTS_N_INSNS (15), /* fp_div_df */ - COSTS_N_INSNS (7), /* int_mult_si */ - COSTS_N_INSNS (7), /* int_mult_di */ - COSTS_N_INSNS (1), /* int_shift */ - COSTS_N_INSNS (2), /* int_cmov */ - }, -}; - -/* Get the number of args of a function in one of two ways. */ -#if TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK -#define NUM_ARGS current_function_args_info.num_args -#else -#define NUM_ARGS current_function_args_info -#endif - -#define REG_PV 27 -#define REG_RA 26 - -/* Declarations of static functions. */ -static struct machine_function *alpha_init_machine_status (void); -static rtx alpha_emit_xfloating_compare (enum rtx_code, rtx, rtx); - -#if TARGET_ABI_OPEN_VMS -static void alpha_write_linkage (FILE *, const char *, tree); -#endif - -static void unicosmk_output_deferred_case_vectors (FILE *); -static void unicosmk_gen_dsib (unsigned long *); -static void unicosmk_output_ssib (FILE *, const char *); -static int unicosmk_need_dex (rtx); - -/* Parse target option strings. */ - -void -override_options (void) -{ - int i; - static const struct cpu_table { - const char *const name; - const enum processor_type processor; - const int flags; - } cpu_table[] = { -#define EV5_MASK (MASK_CPU_EV5) -#define EV6_MASK (MASK_CPU_EV6|MASK_BWX|MASK_MAX|MASK_FIX) - { "ev4", PROCESSOR_EV4, 0 }, - { "ev45", PROCESSOR_EV4, 0 }, - { "21064", PROCESSOR_EV4, 0 }, - { "ev5", PROCESSOR_EV5, EV5_MASK }, - { "21164", PROCESSOR_EV5, EV5_MASK }, - { "ev56", PROCESSOR_EV5, EV5_MASK|MASK_BWX }, - { "21164a", PROCESSOR_EV5, EV5_MASK|MASK_BWX }, - { "pca56", PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX }, - { "21164PC",PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX }, - { "21164pc",PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX }, - { "ev6", PROCESSOR_EV6, EV6_MASK }, - { "21264", PROCESSOR_EV6, EV6_MASK }, - { "ev67", PROCESSOR_EV6, EV6_MASK|MASK_CIX }, - { "21264a", PROCESSOR_EV6, EV6_MASK|MASK_CIX }, - { 0, 0, 0 } - }; - - /* Unicos/Mk doesn't have shared libraries. */ - if (TARGET_ABI_UNICOSMK && flag_pic) - { - warning ("-f%s ignored for Unicos/Mk (not supported)", - (flag_pic > 1) ? "PIC" : "pic"); - flag_pic = 0; - } - - /* On Unicos/Mk, the native compiler consistently generates /d suffices for - floating-point instructions. Make that the default for this target. */ - if (TARGET_ABI_UNICOSMK) - alpha_fprm = ALPHA_FPRM_DYN; - else - alpha_fprm = ALPHA_FPRM_NORM; - - alpha_tp = ALPHA_TP_PROG; - alpha_fptm = ALPHA_FPTM_N; - - /* We cannot use su and sui qualifiers for conversion instructions on - Unicos/Mk. I'm not sure if this is due to assembler or hardware - limitations. Right now, we issue a warning if -mieee is specified - and then ignore it; eventually, we should either get it right or - disable the option altogether. */ - - if (TARGET_IEEE) - { - if (TARGET_ABI_UNICOSMK) - warning ("-mieee not supported on Unicos/Mk"); - else - { - alpha_tp = ALPHA_TP_INSN; - alpha_fptm = ALPHA_FPTM_SU; - } - } - - if (TARGET_IEEE_WITH_INEXACT) - { - if (TARGET_ABI_UNICOSMK) - warning ("-mieee-with-inexact not supported on Unicos/Mk"); - else - { - alpha_tp = ALPHA_TP_INSN; - alpha_fptm = ALPHA_FPTM_SUI; - } - } - - if (alpha_tp_string) - { - if (! strcmp (alpha_tp_string, "p")) - alpha_tp = ALPHA_TP_PROG; - else if (! strcmp (alpha_tp_string, "f")) - alpha_tp = ALPHA_TP_FUNC; - else if (! strcmp (alpha_tp_string, "i")) - alpha_tp = ALPHA_TP_INSN; - else - error ("bad value `%s' for -mtrap-precision switch", alpha_tp_string); - } - - if (alpha_fprm_string) - { - if (! strcmp (alpha_fprm_string, "n")) - alpha_fprm = ALPHA_FPRM_NORM; - else if (! strcmp (alpha_fprm_string, "m")) - alpha_fprm = ALPHA_FPRM_MINF; - else if (! strcmp (alpha_fprm_string, "c")) - alpha_fprm = ALPHA_FPRM_CHOP; - else if (! strcmp (alpha_fprm_string,"d")) - alpha_fprm = ALPHA_FPRM_DYN; - else - error ("bad value `%s' for -mfp-rounding-mode switch", - alpha_fprm_string); - } - - if (alpha_fptm_string) - { - if (strcmp (alpha_fptm_string, "n") == 0) - alpha_fptm = ALPHA_FPTM_N; - else if (strcmp (alpha_fptm_string, "u") == 0) - alpha_fptm = ALPHA_FPTM_U; - else if (strcmp (alpha_fptm_string, "su") == 0) - alpha_fptm = ALPHA_FPTM_SU; - else if (strcmp (alpha_fptm_string, "sui") == 0) - alpha_fptm = ALPHA_FPTM_SUI; - else - error ("bad value `%s' for -mfp-trap-mode switch", alpha_fptm_string); - } - - if (alpha_tls_size_string) - { - if (strcmp (alpha_tls_size_string, "16") == 0) - alpha_tls_size = 16; - else if (strcmp (alpha_tls_size_string, "32") == 0) - alpha_tls_size = 32; - else if (strcmp (alpha_tls_size_string, "64") == 0) - alpha_tls_size = 64; - else - error ("bad value `%s' for -mtls-size switch", alpha_tls_size_string); - } - - alpha_cpu - = TARGET_CPU_DEFAULT & MASK_CPU_EV6 ? PROCESSOR_EV6 - : (TARGET_CPU_DEFAULT & MASK_CPU_EV5 ? PROCESSOR_EV5 : PROCESSOR_EV4); - - if (alpha_cpu_string) - { - for (i = 0; cpu_table [i].name; i++) - if (! strcmp (alpha_cpu_string, cpu_table [i].name)) - { - alpha_cpu = cpu_table [i].processor; - target_flags &= ~ (MASK_BWX | MASK_MAX | MASK_FIX | MASK_CIX - | MASK_CPU_EV5 | MASK_CPU_EV6); - target_flags |= cpu_table [i].flags; - break; - } - if (! cpu_table [i].name) - error ("bad value `%s' for -mcpu switch", alpha_cpu_string); - } - - if (alpha_tune_string) - { - for (i = 0; cpu_table [i].name; i++) - if (! strcmp (alpha_tune_string, cpu_table [i].name)) - { - alpha_cpu = cpu_table [i].processor; - break; - } - if (! cpu_table [i].name) - error ("bad value `%s' for -mcpu switch", alpha_tune_string); - } - - /* Do some sanity checks on the above options. */ - - if (TARGET_ABI_UNICOSMK && alpha_fptm != ALPHA_FPTM_N) - { - warning ("trap mode not supported on Unicos/Mk"); - alpha_fptm = ALPHA_FPTM_N; - } - - if ((alpha_fptm == ALPHA_FPTM_SU || alpha_fptm == ALPHA_FPTM_SUI) - && alpha_tp != ALPHA_TP_INSN && ! TARGET_CPU_EV6) - { - warning ("fp software completion requires -mtrap-precision=i"); - alpha_tp = ALPHA_TP_INSN; - } - - if (TARGET_CPU_EV6) - { - /* Except for EV6 pass 1 (not released), we always have precise - arithmetic traps. Which means we can do software completion - without minding trap shadows. */ - alpha_tp = ALPHA_TP_PROG; - } - - if (TARGET_FLOAT_VAX) - { - if (alpha_fprm == ALPHA_FPRM_MINF || alpha_fprm == ALPHA_FPRM_DYN) - { - warning ("rounding mode not supported for VAX floats"); - alpha_fprm = ALPHA_FPRM_NORM; - } - if (alpha_fptm == ALPHA_FPTM_SUI) - { - warning ("trap mode not supported for VAX floats"); - alpha_fptm = ALPHA_FPTM_SU; - } - if (target_flags_explicit & MASK_LONG_DOUBLE_128) - warning ("128-bit long double not supported for VAX floats"); - target_flags &= ~MASK_LONG_DOUBLE_128; - } - - { - char *end; - int lat; - - if (!alpha_mlat_string) - alpha_mlat_string = "L1"; - - if (ISDIGIT ((unsigned char)alpha_mlat_string[0]) - && (lat = strtol (alpha_mlat_string, &end, 10), *end == '\0')) - ; - else if ((alpha_mlat_string[0] == 'L' || alpha_mlat_string[0] == 'l') - && ISDIGIT ((unsigned char)alpha_mlat_string[1]) - && alpha_mlat_string[2] == '\0') - { - static int const cache_latency[][4] = - { - { 3, 30, -1 }, /* ev4 -- Bcache is a guess */ - { 2, 12, 38 }, /* ev5 -- Bcache from PC164 LMbench numbers */ - { 3, 12, 30 }, /* ev6 -- Bcache from DS20 LMbench. */ - }; - - lat = alpha_mlat_string[1] - '0'; - if (lat <= 0 || lat > 3 || cache_latency[alpha_cpu][lat-1] == -1) - { - warning ("L%d cache latency unknown for %s", - lat, alpha_cpu_name[alpha_cpu]); - lat = 3; - } - else - lat = cache_latency[alpha_cpu][lat-1]; - } - else if (! strcmp (alpha_mlat_string, "main")) - { - /* Most current memories have about 370ns latency. This is - a reasonable guess for a fast cpu. */ - lat = 150; - } - else - { - warning ("bad value `%s' for -mmemory-latency", alpha_mlat_string); - lat = 3; - } - - alpha_memory_latency = lat; - } - - /* Default the definition of "small data" to 8 bytes. */ - if (!g_switch_set) - g_switch_value = 8; - - /* Infer TARGET_SMALL_DATA from -fpic/-fPIC. */ - if (flag_pic == 1) - target_flags |= MASK_SMALL_DATA; - else if (flag_pic == 2) - target_flags &= ~MASK_SMALL_DATA; - - /* Align labels and loops for optimal branching. */ - /* ??? Kludge these by not doing anything if we don't optimize and also if - we are writing ECOFF symbols to work around a bug in DEC's assembler. */ - if (optimize > 0 && write_symbols != SDB_DEBUG) - { - if (align_loops <= 0) - align_loops = 16; - if (align_jumps <= 0) - align_jumps = 16; - } - if (align_functions <= 0) - align_functions = 16; - - /* Acquire a unique set number for our register saves and restores. */ - alpha_sr_alias_set = new_alias_set (); - - /* Register variables and functions with the garbage collector. */ - - /* Set up function hooks. */ - init_machine_status = alpha_init_machine_status; - - /* Tell the compiler when we're using VAX floating point. */ - if (TARGET_FLOAT_VAX) - { - REAL_MODE_FORMAT (SFmode) = &vax_f_format; - REAL_MODE_FORMAT (DFmode) = &vax_g_format; - REAL_MODE_FORMAT (TFmode) = NULL; - } -} - -/* Returns 1 if VALUE is a mask that contains full bytes of zero or ones. */ - -int -zap_mask (HOST_WIDE_INT value) -{ - int i; - - for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; - i++, value >>= 8) - if ((value & 0xff) != 0 && (value & 0xff) != 0xff) - return 0; - - return 1; -} - -/* Returns 1 if OP is either the constant zero or a register. If a - register, it must be in the proper mode unless MODE is VOIDmode. */ - -int -reg_or_0_operand (rtx op, enum machine_mode mode) -{ - return op == CONST0_RTX (mode) || register_operand (op, mode); -} - -/* Return 1 if OP is a constant in the range of 0-63 (for a shift) or - any register. */ - -int -reg_or_6bit_operand (rtx op, enum machine_mode mode) -{ - return ((GET_CODE (op) == CONST_INT - && (unsigned HOST_WIDE_INT) INTVAL (op) < 64) - || register_operand (op, mode)); -} - - -/* Return 1 if OP is an 8-bit constant or any register. */ - -int -reg_or_8bit_operand (rtx op, enum machine_mode mode) -{ - return ((GET_CODE (op) == CONST_INT - && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100) - || register_operand (op, mode)); -} - -/* Return 1 if OP is a constant or any register. */ - -int -reg_or_const_int_operand (rtx op, enum machine_mode mode) -{ - return GET_CODE (op) == CONST_INT || register_operand (op, mode); -} - -/* Return 1 if OP is an 8-bit constant. */ - -int -cint8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - return ((GET_CODE (op) == CONST_INT - && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)); -} - -/* Return 1 if the operand is a valid second operand to an add insn. */ - -int -add_operand (rtx op, enum machine_mode mode) -{ - if (GET_CODE (op) == CONST_INT) - /* Constraints I, J, O and P are covered by K. */ - return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K') - || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); - - return register_operand (op, mode); -} - -/* Return 1 if the operand is a valid second operand to a sign-extending - add insn. */ - -int -sext_add_operand (rtx op, enum machine_mode mode) -{ - if (GET_CODE (op) == CONST_INT) - return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') - || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O')); - - return reg_not_elim_operand (op, mode); -} - -/* Return 1 if OP is the constant 4 or 8. */ - -int -const48_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - return (GET_CODE (op) == CONST_INT - && (INTVAL (op) == 4 || INTVAL (op) == 8)); -} - -/* Return 1 if OP is a valid first operand to an AND insn. */ - -int -and_operand (rtx op, enum machine_mode mode) -{ - if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode) - return (zap_mask (CONST_DOUBLE_LOW (op)) - && zap_mask (CONST_DOUBLE_HIGH (op))); - - if (GET_CODE (op) == CONST_INT) - return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100 - || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100 - || zap_mask (INTVAL (op))); - - return register_operand (op, mode); -} - -/* Return 1 if OP is a valid first operand to an IOR or XOR insn. */ - -int -or_operand (rtx op, enum machine_mode mode) -{ - if (GET_CODE (op) == CONST_INT) - return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100 - || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100); - - return register_operand (op, mode); -} - -/* Return 1 if OP is a constant that is the width, in bits, of an integral - mode smaller than DImode. */ - -int -mode_width_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - return (GET_CODE (op) == CONST_INT - && (INTVAL (op) == 8 || INTVAL (op) == 16 - || INTVAL (op) == 32 || INTVAL (op) == 64)); -} - -/* Return 1 if OP is a constant that is the width of an integral machine mode - smaller than an integer. */ - -int -mode_mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - if (GET_CODE (op) == CONST_INT) - { - HOST_WIDE_INT value = INTVAL (op); - - if (value == 0xff) - return 1; - if (value == 0xffff) - return 1; - if (value == 0xffffffff) - return 1; - if (value == -1) - return 1; - } - else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE) - { - if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0) - return 1; - } - - return 0; -} - -/* Return 1 if OP is a multiple of 8 less than 64. */ - -int -mul8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - return (GET_CODE (op) == CONST_INT - && (unsigned HOST_WIDE_INT) INTVAL (op) < 64 - && (INTVAL (op) & 7) == 0); -} - -/* Return 1 if OP is the zero constant for MODE. */ - -int -const0_operand (rtx op, enum machine_mode mode) -{ - return op == CONST0_RTX (mode); -} - -/* Return 1 if OP is a hard floating-point register. */ - -int -hard_fp_register_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_CODE (op) == SUBREG) - op = SUBREG_REG (op); - return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS; -} - -/* Return 1 if OP is a hard general register. */ - -int -hard_int_register_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_CODE (op) == SUBREG) - op = SUBREG_REG (op); - return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS; -} - -/* Return 1 if OP is a register or a constant integer. */ - - -int -reg_or_cint_operand (rtx op, enum machine_mode mode) -{ - return (GET_CODE (op) == CONST_INT - || register_operand (op, mode)); -} - -/* Return 1 if OP is something that can be reloaded into a register; - if it is a MEM, it need not be valid. */ - -int -some_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - switch (GET_CODE (op)) - { - case REG: - case MEM: - case CONST_INT: - case CONST_DOUBLE: - case CONST_VECTOR: - case LABEL_REF: - case SYMBOL_REF: - case CONST: - case HIGH: - return 1; - - case SUBREG: - return some_operand (SUBREG_REG (op), VOIDmode); - - default: - break; - } - - return 0; -} - -/* Likewise, but don't accept constants. */ - -int -some_ni_operand (rtx op, enum machine_mode mode) -{ - if (GET_MODE (op) != mode && mode != VOIDmode) - return 0; - - if (GET_CODE (op) == SUBREG) - op = SUBREG_REG (op); - - return (GET_CODE (op) == REG || GET_CODE (op) == MEM); -} - -/* Return 1 if OP is a valid operand for the source of a move insn. */ - -int -input_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode) - return 0; - - switch (GET_CODE (op)) - { - case LABEL_REF: - case SYMBOL_REF: - case CONST: - if (TARGET_EXPLICIT_RELOCS) - { - /* We don't split symbolic operands into something unintelligable - until after reload, but we do not wish non-small, non-global - symbolic operands to be reconstructed from their high/lo_sum - form. */ - return (small_symbolic_operand (op, mode) - || global_symbolic_operand (op, mode) - || gotdtp_symbolic_operand (op, mode) - || gottp_symbolic_operand (op, mode)); - } - - /* This handles both the Windows/NT and OSF cases. */ - return mode == ptr_mode || mode == DImode; - - case HIGH: - return (TARGET_EXPLICIT_RELOCS - && local_symbolic_operand (XEXP (op, 0), mode)); - - case REG: - case ADDRESSOF: - return 1; - - case SUBREG: - if (register_operand (op, mode)) - return 1; - /* ... fall through ... */ - case MEM: - return ((TARGET_BWX || (mode != HImode && mode != QImode)) - && general_operand (op, mode)); - - case CONST_DOUBLE: - case CONST_VECTOR: - return op == CONST0_RTX (mode); - - case CONST_INT: - return mode == QImode || mode == HImode || add_operand (op, mode); - - case CONSTANT_P_RTX: - return 1; - - default: - break; - } - - return 0; -} - -/* Return 1 if OP is a SYMBOL_REF for a function known to be in this - file, and in the same section as the current function. */ - -int -samegp_function_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - if (GET_CODE (op) != SYMBOL_REF) - return false; - - /* Easy test for recursion. */ - if (op == XEXP (DECL_RTL (current_function_decl), 0)) - return true; - - /* Functions that are not local can be overridden, and thus may - not share the same gp. */ - if (! SYMBOL_REF_LOCAL_P (op)) - return false; - - /* If -msmall-data is in effect, assume that there is only one GP - for the module, and so any local symbol has this property. We - need explicit relocations to be able to enforce this for symbols - not defined in this unit of translation, however. */ - if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA) - return true; - - /* Functions that are not external are defined in this UoT, - and thus must share the same gp. */ - return ! SYMBOL_REF_EXTERNAL_P (op); -} - -/* Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr. */ - -int -direct_call_operand (rtx op, enum machine_mode mode) -{ - tree op_decl, cfun_sec, op_sec; - - /* Must share the same GP. */ - if (!samegp_function_operand (op, mode)) - return false; - - /* If profiling is implemented via linker tricks, we can't jump - to the nogp alternate entry point. Note that current_function_profile - would not be correct, since that doesn't indicate if the target - function uses profiling. */ - /* ??? TARGET_PROFILING_NEEDS_GP isn't really the right test, - but is approximately correct for the OSF ABIs. Don't know - what to do for VMS, NT, or UMK. */ - if (!TARGET_PROFILING_NEEDS_GP && profile_flag) - return false; - - /* Must be a function. In some cases folks create thunks in static - data structures and then make calls to them. If we allow the - direct call, we'll get an error from the linker about !samegp reloc - against a symbol without a .prologue directive. */ - if (!SYMBOL_REF_FUNCTION_P (op)) - return false; - - /* Must be "near" so that the branch is assumed to reach. With - -msmall-text, this is assumed true of all local symbols. Since - we've already checked samegp, locality is already assured. */ - if (TARGET_SMALL_TEXT) - return true; - - /* Otherwise, a decl is "near" if it is defined in the same section. */ - if (flag_function_sections) - return false; - - op_decl = SYMBOL_REF_DECL (op); - if (DECL_ONE_ONLY (current_function_decl) - || (op_decl && DECL_ONE_ONLY (op_decl))) - return false; - - cfun_sec = DECL_SECTION_NAME (current_function_decl); - op_sec = op_decl ? DECL_SECTION_NAME (op_decl) : NULL; - return ((!cfun_sec && !op_sec) - || (cfun_sec && op_sec - && strcmp (TREE_STRING_POINTER (cfun_sec), - TREE_STRING_POINTER (op_sec)) == 0)); -} - -/* Return true if OP is a LABEL_REF, or SYMBOL_REF or CONST referencing - a (non-tls) variable known to be defined in this file. */ - -int -local_symbolic_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_CODE (op) == LABEL_REF) - return 1; - - if (GET_CODE (op) == CONST - && GET_CODE (XEXP (op, 0)) == PLUS - && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT) - op = XEXP (XEXP (op, 0), 0); - - if (GET_CODE (op) != SYMBOL_REF) - return 0; - - return SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op); -} - -/* Return true if OP is a SYMBOL_REF or CONST referencing a variable - known to be defined in this file in the small data area. */ - -int -small_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - if (! TARGET_SMALL_DATA) - return 0; - - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_CODE (op) == CONST - && GET_CODE (XEXP (op, 0)) == PLUS - && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT) - op = XEXP (XEXP (op, 0), 0); - - if (GET_CODE (op) != SYMBOL_REF) - return 0; - - /* ??? There's no encode_section_info equivalent for the rtl - constant pool, so SYMBOL_FLAG_SMALL never gets set. */ - if (CONSTANT_POOL_ADDRESS_P (op)) - return GET_MODE_SIZE (get_pool_mode (op)) <= g_switch_value; - - return (SYMBOL_REF_LOCAL_P (op) - && SYMBOL_REF_SMALL_P (op) - && SYMBOL_REF_TLS_MODEL (op) == 0); -} - -/* Return true if OP is a SYMBOL_REF or CONST referencing a variable - not known (or known not) to be defined in this file. */ - -int -global_symbolic_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_CODE (op) == CONST - && GET_CODE (XEXP (op, 0)) == PLUS - && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT) - op = XEXP (XEXP (op, 0), 0); - - if (GET_CODE (op) != SYMBOL_REF) - return 0; - - return !SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op); -} - -/* Return 1 if OP is a valid operand for the MEM of a CALL insn. */ - -int -call_operand (rtx op, enum machine_mode mode) -{ - if (mode != Pmode) - return 0; - - if (GET_CODE (op) == REG) - { - if (TARGET_ABI_OSF) - { - /* Disallow virtual registers to cope with pathological test cases - such as compile/930117-1.c in which the virtual reg decomposes - to the frame pointer. Which is a hard reg that is not $27. */ - return (REGNO (op) == 27 || REGNO (op) > LAST_VIRTUAL_REGISTER); - } - else - return 1; - } - if (TARGET_ABI_UNICOSMK) - return 0; - if (GET_CODE (op) == SYMBOL_REF) - return 1; - - return 0; -} - -/* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref, - possibly with an offset. */ - -int -symbolic_operand (rtx op, enum machine_mode mode) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF) - return 1; - if (GET_CODE (op) == CONST - && GET_CODE (XEXP (op,0)) == PLUS - && GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF - && GET_CODE (XEXP (XEXP (op,0), 1)) == CONST_INT) - return 1; - return 0; -} - -/* Return true if OP is valid for a particular TLS relocation. */ - -static int -tls_symbolic_operand_1 (rtx op, enum machine_mode mode, int size, int unspec) -{ - if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op)) - return 0; - - if (GET_CODE (op) != CONST) - return 0; - op = XEXP (op, 0); - - if (GET_CODE (op) != UNSPEC || XINT (op, 1) != unspec) - return 0; - op = XVECEXP (op, 0, 0); - - if (GET_CODE (op) != SYMBOL_REF) - return 0; - - if (SYMBOL_REF_LOCAL_P (op)) - { - if (alpha_tls_size > size) - return 0; - } - else - { - if (size != 64) - return 0; - } - - switch (SYMBOL_REF_TLS_MODEL (op)) - { - case TLS_MODEL_LOCAL_DYNAMIC: - return unspec == UNSPEC_DTPREL; - case TLS_MODEL_INITIAL_EXEC: - return unspec == UNSPEC_TPREL && size == 64; - case TLS_MODEL_LOCAL_EXEC: - return unspec == UNSPEC_TPREL; - default: - abort (); - } -} - -/* Return true if OP is valid for 16-bit DTP relative relocations. */ - -int -dtp16_symbolic_operand (rtx op, enum machine_mode mode) -{ - return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_DTPREL); -} - -/* Return true if OP is valid for 32-bit DTP relative relocations. */ - -int -dtp32_symbolic_operand (rtx op, enum machine_mode mode) -{ - return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_DTPREL); -} - -/* Return true if OP is valid for 64-bit DTP relative relocations. */ - -int -gotdtp_symbolic_operand (rtx op, enum machine_mode mode) -{ - return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_DTPREL); -} - -/* Return true if OP is valid for 16-bit TP relative relocations. */ - -int -tp16_symbolic_operand (rtx op, enum machine_mode mode) -{ - return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_TPREL); -} - -/* Return true if OP is valid for 32-bit TP relative relocations. */ - -int -tp32_symbolic_operand (rtx op, enum machine_mode mode) -{ - return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_TPREL); -} - -/* Return true if OP is valid for 64-bit TP relative relocations. */ - -int -gottp_symbolic_operand (rtx op, enum machine_mode mode) -{ - return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_TPREL); -} - -/* Return 1 if OP is a valid Alpha comparison operator. Here we know which - comparisons are valid in which insn. */ - -int -alpha_comparison_operator (rtx op, enum machine_mode mode) -{ - enum rtx_code code = GET_CODE (op); - - if (mode != GET_MODE (op) && mode != VOIDmode) - return 0; - - return (code == EQ || code == LE || code == LT - || code == LEU || code == LTU); -} - -/* Return 1 if OP is a valid Alpha comparison operator against zero. - Here we know which comparisons are valid in which insn. */ - -int -alpha_zero_comparison_operator (rtx op, enum machine_mode mode) -{ - enum rtx_code code = GET_CODE (op); - - if (mode != GET_MODE (op) && mode != VOIDmode) - return 0; - - return (code == EQ || code == NE || code == LE || code == LT - || code == LEU || code == LTU); -} - -/* Return 1 if OP is a valid Alpha swapped comparison operator. */ - -int -alpha_swapped_comparison_operator (rtx op, enum machine_mode mode) -{ - enum rtx_code code = GET_CODE (op); - - if ((mode != GET_MODE (op) && mode != VOIDmode) - || GET_RTX_CLASS (code) != '<') - return 0; - - code = swap_condition (code); - return (code == EQ || code == LE || code == LT - || code == LEU || code == LTU); -} - -/* Return 1 if OP is a signed comparison operation. */ - -int -signed_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - enum rtx_code code = GET_CODE (op); - - if (mode != GET_MODE (op) && mode != VOIDmode) - return 0; - - return (code == EQ || code == NE - || code == LE || code == LT - || code == GE || code == GT); -} - -/* Return 1 if OP is a valid Alpha floating point comparison operator. - Here we know which comparisons are valid in which insn. */ - -int -alpha_fp_comparison_operator (rtx op, enum machine_mode mode) -{ - enum rtx_code code = GET_CODE (op); - - if (mode != GET_MODE (op) && mode != VOIDmode) - return 0; - - return (code == EQ || code == LE || code == LT || code == UNORDERED); -} - -/* Return 1 if this is a divide or modulus operator. */ - -int -divmod_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - enum rtx_code code = GET_CODE (op); - - return (code == DIV || code == MOD || code == UDIV || code == UMOD); -} - -/* Return 1 if this is a float->int conversion operator. */ - -int -fix_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - enum rtx_code code = GET_CODE (op); - - return (code == FIX || code == UNSIGNED_FIX); -} - -/* Return 1 if this memory address is a known aligned register plus - a constant. It must be a valid address. This means that we can do - this as an aligned reference plus some offset. - - Take into account what reload will do. */ - -int -aligned_memory_operand (rtx op, enum machine_mode mode) -{ - rtx base; - - if (reload_in_progress) - { - rtx tmp = op; - if (GET_CODE (tmp) == SUBREG) - tmp = SUBREG_REG (tmp); - if (GET_CODE (tmp) == REG - && REGNO (tmp) >= FIRST_PSEUDO_REGISTER) - { - op = reg_equiv_memory_loc[REGNO (tmp)]; - if (op == 0) - return 0; - } - } - - if (GET_CODE (op) != MEM) - return 0; - if (MEM_ALIGN (op) >= 32) - return 1; - op = XEXP (op, 0); - - /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo) - sorts of constructs. Dig for the real base register. */ - if (reload_in_progress - && GET_CODE (op) == PLUS - && GET_CODE (XEXP (op, 0)) == PLUS) - base = XEXP (XEXP (op, 0), 0); - else - { - if (! memory_address_p (mode, op)) - return 0; - base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op); - } - - return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) >= 32); -} - -/* Similar, but return 1 if OP is a MEM which is not alignable. */ - -int -unaligned_memory_operand (rtx op, enum machine_mode mode) -{ - rtx base; - - if (reload_in_progress) - { - rtx tmp = op; - if (GET_CODE (tmp) == SUBREG) - tmp = SUBREG_REG (tmp); - if (GET_CODE (tmp) == REG - && REGNO (tmp) >= FIRST_PSEUDO_REGISTER) - { - op = reg_equiv_memory_loc[REGNO (tmp)]; - if (op == 0) - return 0; - } - } - - if (GET_CODE (op) != MEM) - return 0; - if (MEM_ALIGN (op) >= 32) - return 0; - op = XEXP (op, 0); - - /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo) - sorts of constructs. Dig for the real base register. */ - if (reload_in_progress - && GET_CODE (op) == PLUS - && GET_CODE (XEXP (op, 0)) == PLUS) - base = XEXP (XEXP (op, 0), 0); - else - { - if (! memory_address_p (mode, op)) - return 0; - base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op); - } - - return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) < 32); -} - -/* Return 1 if OP is either a register or an unaligned memory location. */ - -int -reg_or_unaligned_mem_operand (rtx op, enum machine_mode mode) -{ - return register_operand (op, mode) || unaligned_memory_operand (op, mode); -} - -/* Return 1 if OP is any memory location. During reload a pseudo matches. */ - -int -any_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - return (GET_CODE (op) == MEM - || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG) - || (reload_in_progress && GET_CODE (op) == REG - && REGNO (op) >= FIRST_PSEUDO_REGISTER) - || (reload_in_progress && GET_CODE (op) == SUBREG - && GET_CODE (SUBREG_REG (op)) == REG - && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER)); -} - -/* Returns 1 if OP is not an eliminable register. - - This exists to cure a pathological abort in the s8addq (et al) patterns, - - long foo () { long t; bar(); return (long) &t * 26107; } - - which run afoul of a hack in reload to cure a (presumably) similar - problem with lea-type instructions on other targets. But there is - one of us and many of them, so work around the problem by selectively - preventing combine from making the optimization. */ - -int -reg_not_elim_operand (rtx op, enum machine_mode mode) -{ - rtx inner = op; - if (GET_CODE (op) == SUBREG) - inner = SUBREG_REG (op); - if (inner == frame_pointer_rtx || inner == arg_pointer_rtx) - return 0; - - return register_operand (op, mode); -} - -/* Return 1 is OP is a memory location that is not a reference (using - an AND) to an unaligned location. Take into account what reload - will do. */ - -int -normal_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - if (reload_in_progress) - { - rtx tmp = op; - if (GET_CODE (tmp) == SUBREG) - tmp = SUBREG_REG (tmp); - if (GET_CODE (tmp) == REG - && REGNO (tmp) >= FIRST_PSEUDO_REGISTER) - { - op = reg_equiv_memory_loc[REGNO (tmp)]; - - /* This may not have been assigned an equivalent address if it will - be eliminated. In that case, it doesn't matter what we do. */ - if (op == 0) - return 1; - } - } - - return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) != AND; -} - -/* Accept a register, but not a subreg of any kind. This allows us to - avoid pathological cases in reload wrt data movement common in - int->fp conversion. */ - -int -reg_no_subreg_operand (rtx op, enum machine_mode mode) -{ - if (GET_CODE (op) != REG) - return 0; - return register_operand (op, mode); -} - -/* Recognize an addition operation that includes a constant. Used to - convince reload to canonize (plus (plus reg c1) c2) during register - elimination. */ - -int -addition_operation (rtx op, enum machine_mode mode) -{ - if (GET_MODE (op) != mode && mode != VOIDmode) - return 0; - if (GET_CODE (op) == PLUS - && register_operand (XEXP (op, 0), mode) - && GET_CODE (XEXP (op, 1)) == CONST_INT - && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op, 1)), 'K')) - return 1; - return 0; -} - -/* Implements CONST_OK_FOR_LETTER_P. Return true if the value matches - the range defined for C in [I-P]. */ - -bool -alpha_const_ok_for_letter_p (HOST_WIDE_INT value, int c) -{ - switch (c) - { - case 'I': - /* An unsigned 8 bit constant. */ - return (unsigned HOST_WIDE_INT) value < 0x100; - case 'J': - /* The constant zero. */ - return value == 0; - case 'K': - /* A signed 16 bit constant. */ - return (unsigned HOST_WIDE_INT) (value + 0x8000) < 0x10000; - case 'L': - /* A shifted signed 16 bit constant appropriate for LDAH. */ - return ((value & 0xffff) == 0 - && ((value) >> 31 == -1 || value >> 31 == 0)); - case 'M': - /* A constant that can be AND'ed with using a ZAP insn. */ - return zap_mask (value); - case 'N': - /* A complemented unsigned 8 bit constant. */ - return (unsigned HOST_WIDE_INT) (~ value) < 0x100; - case 'O': - /* A negated unsigned 8 bit constant. */ - return (unsigned HOST_WIDE_INT) (- value) < 0x100; - case 'P': - /* The constant 1, 2 or 3. */ - return value == 1 || value == 2 || value == 3; - - default: - return false; - } -} - -/* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE - matches for C in [GH]. */ - -bool -alpha_const_double_ok_for_letter_p (rtx value, int c) -{ - switch (c) - { - case 'G': - /* The floating point zero constant. */ - return (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT - && value == CONST0_RTX (GET_MODE (value))); - - case 'H': - /* A valid operand of a ZAP insn. */ - return (GET_MODE (value) == VOIDmode - && zap_mask (CONST_DOUBLE_LOW (value)) - && zap_mask (CONST_DOUBLE_HIGH (value))); - - default: - return false; - } -} - -/* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE - matches for C. */ - -bool -alpha_extra_constraint (rtx value, int c) -{ - switch (c) - { - case 'Q': - return normal_memory_operand (value, VOIDmode); - case 'R': - return direct_call_operand (value, Pmode); - case 'S': - return (GET_CODE (value) == CONST_INT - && (unsigned HOST_WIDE_INT) INTVAL (value) < 64); - case 'T': - return GET_CODE (value) == HIGH; - case 'U': - return TARGET_ABI_UNICOSMK && symbolic_operand (value, VOIDmode); - case 'W': - return (GET_CODE (value) == CONST_VECTOR - && value == CONST0_RTX (GET_MODE (value))); - default: - return false; - } -} - -/* Return 1 if this function can directly return via $26. */ - -int -direct_return (void) -{ - return (! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK - && reload_completed - && alpha_sa_size () == 0 - && get_frame_size () == 0 - && current_function_outgoing_args_size == 0 - && current_function_pretend_args_size == 0); -} - -/* Return the ADDR_VEC associated with a tablejump insn. */ - -rtx -alpha_tablejump_addr_vec (rtx insn) -{ - rtx tmp; - - tmp = JUMP_LABEL (insn); - if (!tmp) - return NULL_RTX; - tmp = NEXT_INSN (tmp); - if (!tmp) - return NULL_RTX; - if (GET_CODE (tmp) == JUMP_INSN - && GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC) - return PATTERN (tmp); - return NULL_RTX; -} - -/* Return the label of the predicted edge, or CONST0_RTX if we don't know. */ - -rtx -alpha_tablejump_best_label (rtx insn) -{ - rtx jump_table = alpha_tablejump_addr_vec (insn); - rtx best_label = NULL_RTX; - - /* ??? Once the CFG doesn't keep getting completely rebuilt, look - there for edge frequency counts from profile data. */ - - if (jump_table) - { - int n_labels = XVECLEN (jump_table, 1); - int best_count = -1; - int i, j; - - for (i = 0; i < n_labels; i++) - { - int count = 1; - - for (j = i + 1; j < n_labels; j++) - if (XEXP (XVECEXP (jump_table, 1, i), 0) - == XEXP (XVECEXP (jump_table, 1, j), 0)) - count++; - - if (count > best_count) - best_count = count, best_label = XVECEXP (jump_table, 1, i); - } - } - - return best_label ? best_label : const0_rtx; -} - -/* Return the TLS model to use for SYMBOL. */ - -static enum tls_model -tls_symbolic_operand_type (rtx symbol) -{ - enum tls_model model; - - if (GET_CODE (symbol) != SYMBOL_REF) - return 0; - model = SYMBOL_REF_TLS_MODEL (symbol); - - /* Local-exec with a 64-bit size is the same code as initial-exec. */ - if (model == TLS_MODEL_LOCAL_EXEC && alpha_tls_size == 64) - model = TLS_MODEL_INITIAL_EXEC; - - return model; -} - -/* Return true if the function DECL will share the same GP as any - function in the current unit of translation. */ - -static bool -decl_has_samegp (tree decl) -{ - /* Functions that are not local can be overridden, and thus may - not share the same gp. */ - if (!(*targetm.binds_local_p) (decl)) - return false; - - /* If -msmall-data is in effect, assume that there is only one GP - for the module, and so any local symbol has this property. We - need explicit relocations to be able to enforce this for symbols - not defined in this unit of translation, however. */ - if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA) - return true; - - /* Functions that are not external are defined in this UoT. */ - /* ??? Irritatingly, static functions not yet emitted are still - marked "external". Apply this to non-static functions only. */ - return !TREE_PUBLIC (decl) || !DECL_EXTERNAL (decl); -} - -/* Return true if EXP should be placed in the small data section. */ - -static bool -alpha_in_small_data_p (tree exp) -{ - /* We want to merge strings, so we never consider them small data. */ - if (TREE_CODE (exp) == STRING_CST) - return false; - - /* Functions are never in the small data area. Duh. */ - if (TREE_CODE (exp) == FUNCTION_DECL) - return false; - - if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp)) - { - const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp)); - if (strcmp (section, ".sdata") == 0 - || strcmp (section, ".sbss") == 0) - return true; - } - else - { - HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); - - /* If this is an incomplete type with size 0, then we can't put it - in sdata because it might be too big when completed. */ - if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value) - return true; - } - - return false; -} - -#if TARGET_ABI_OPEN_VMS -static bool -alpha_linkage_symbol_p (const char *symname) -{ - int symlen = strlen (symname); - - if (symlen > 4) - return strcmp (&symname [symlen - 4], "..lk") == 0; - - return false; -} - -#define LINKAGE_SYMBOL_REF_P(X) \ - ((GET_CODE (X) == SYMBOL_REF \ - && alpha_linkage_symbol_p (XSTR (X, 0))) \ - || (GET_CODE (X) == CONST \ - && GET_CODE (XEXP (X, 0)) == PLUS \ - && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF \ - && alpha_linkage_symbol_p (XSTR (XEXP (XEXP (X, 0), 0), 0)))) -#endif - -/* legitimate_address_p recognizes an RTL expression that is a valid - memory address for an instruction. The MODE argument is the - machine mode for the MEM expression that wants to use this address. - - For Alpha, we have either a constant address or the sum of a - register and a constant address, or just a register. For DImode, - any of those forms can be surrounded with an AND that clear the - low-order three bits; this is an "unaligned" access. */ - -bool -alpha_legitimate_address_p (enum machine_mode mode, rtx x, int strict) -{ - /* If this is an ldq_u type address, discard the outer AND. */ - if (mode == DImode - && GET_CODE (x) == AND - && GET_CODE (XEXP (x, 1)) == CONST_INT - && INTVAL (XEXP (x, 1)) == -8) - x = XEXP (x, 0); - - /* Discard non-paradoxical subregs. */ - if (GET_CODE (x) == SUBREG - && (GET_MODE_SIZE (GET_MODE (x)) - < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) - x = SUBREG_REG (x); - - /* Unadorned general registers are valid. */ - if (REG_P (x) - && (strict - ? STRICT_REG_OK_FOR_BASE_P (x) - : NONSTRICT_REG_OK_FOR_BASE_P (x))) - return true; - - /* Constant addresses (i.e. +/- 32k) are valid. */ - if (CONSTANT_ADDRESS_P (x)) - return true; - -#if TARGET_ABI_OPEN_VMS - if (LINKAGE_SYMBOL_REF_P (x)) - return true; -#endif - - /* Register plus a small constant offset is valid. */ - if (GET_CODE (x) == PLUS) - { - rtx ofs = XEXP (x, 1); - x = XEXP (x, 0); - - /* Discard non-paradoxical subregs. */ - if (GET_CODE (x) == SUBREG - && (GET_MODE_SIZE (GET_MODE (x)) - < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) - x = SUBREG_REG (x); - - if (REG_P (x)) - { - if (! strict - && NONSTRICT_REG_OK_FP_BASE_P (x) - && GET_CODE (ofs) == CONST_INT) - return true; - if ((strict - ? STRICT_REG_OK_FOR_BASE_P (x) - : NONSTRICT_REG_OK_FOR_BASE_P (x)) - && CONSTANT_ADDRESS_P (ofs)) - return true; - } - else if (GET_CODE (x) == ADDRESSOF - && GET_CODE (ofs) == CONST_INT) - return true; - } - - /* If we're managing explicit relocations, LO_SUM is valid, as - are small data symbols. */ - else if (TARGET_EXPLICIT_RELOCS) - { - if (small_symbolic_operand (x, Pmode)) - return true; - - if (GET_CODE (x) == LO_SUM) - { - rtx ofs = XEXP (x, 1); - x = XEXP (x, 0); - - /* Discard non-paradoxical subregs. */ - if (GET_CODE (x) == SUBREG - && (GET_MODE_SIZE (GET_MODE (x)) - < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) - x = SUBREG_REG (x); - - /* Must have a valid base register. */ - if (! (REG_P (x) - && (strict - ? STRICT_REG_OK_FOR_BASE_P (x) - : NONSTRICT_REG_OK_FOR_BASE_P (x)))) - return false; - - /* The symbol must be local. */ - if (local_symbolic_operand (ofs, Pmode) - || dtp32_symbolic_operand (ofs, Pmode) - || tp32_symbolic_operand (ofs, Pmode)) - return true; - } - } - - return false; -} - -/* Build the SYMBOL_REF for __tls_get_addr. */ - -static GTY(()) rtx tls_get_addr_libfunc; - -static rtx -get_tls_get_addr (void) -{ - if (!tls_get_addr_libfunc) - tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr"); - return tls_get_addr_libfunc; -} - -/* Try machine-dependent ways of modifying an illegitimate address - to be legitimate. If we find one, return the new, valid address. */ - -rtx -alpha_legitimize_address (rtx x, rtx scratch, - enum machine_mode mode ATTRIBUTE_UNUSED) -{ - HOST_WIDE_INT addend; - - /* If the address is (plus reg const_int) and the CONST_INT is not a - valid offset, compute the high part of the constant and add it to - the register. Then our address is (plus temp low-part-const). */ - if (GET_CODE (x) == PLUS - && GET_CODE (XEXP (x, 0)) == REG - && GET_CODE (XEXP (x, 1)) == CONST_INT - && ! CONSTANT_ADDRESS_P (XEXP (x, 1))) - { - addend = INTVAL (XEXP (x, 1)); - x = XEXP (x, 0); - goto split_addend; - } - - /* If the address is (const (plus FOO const_int)), find the low-order - part of the CONST_INT. Then load FOO plus any high-order part of the - CONST_INT into a register. Our address is (plus reg low-part-const). - This is done to reduce the number of GOT entries. */ - if (!no_new_pseudos - && GET_CODE (x) == CONST - && GET_CODE (XEXP (x, 0)) == PLUS - && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT) - { - addend = INTVAL (XEXP (XEXP (x, 0), 1)); - x = force_reg (Pmode, XEXP (XEXP (x, 0), 0)); - goto split_addend; - } - - /* If we have a (plus reg const), emit the load as in (2), then add - the two registers, and finally generate (plus reg low-part-const) as - our address. */ - if (!no_new_pseudos - && GET_CODE (x) == PLUS - && GET_CODE (XEXP (x, 0)) == REG - && GET_CODE (XEXP (x, 1)) == CONST - && GET_CODE (XEXP (XEXP (x, 1), 0)) == PLUS - && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == CONST_INT) - { - addend = INTVAL (XEXP (XEXP (XEXP (x, 1), 0), 1)); - x = expand_simple_binop (Pmode, PLUS, XEXP (x, 0), - XEXP (XEXP (XEXP (x, 1), 0), 0), - NULL_RTX, 1, OPTAB_LIB_WIDEN); - goto split_addend; - } - - /* If this is a local symbol, split the address into HIGH/LO_SUM parts. */ - if (TARGET_EXPLICIT_RELOCS && symbolic_operand (x, Pmode)) - { - rtx r0, r16, eqv, tga, tp, insn, dest, seq; - - switch (tls_symbolic_operand_type (x)) - { - case TLS_MODEL_GLOBAL_DYNAMIC: - start_sequence (); - - r0 = gen_rtx_REG (Pmode, 0); - r16 = gen_rtx_REG (Pmode, 16); - tga = get_tls_get_addr (); - dest = gen_reg_rtx (Pmode); - seq = GEN_INT (alpha_next_sequence_number++); - - emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq)); - insn = gen_call_value_osf_tlsgd (r0, tga, seq); - insn = emit_call_insn (insn); - CONST_OR_PURE_CALL_P (insn) = 1; - use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16); - - insn = get_insns (); - end_sequence (); - - emit_libcall_block (insn, dest, r0, x); - return dest; - - case TLS_MODEL_LOCAL_DYNAMIC: - start_sequence (); - - r0 = gen_rtx_REG (Pmode, 0); - r16 = gen_rtx_REG (Pmode, 16); - tga = get_tls_get_addr (); - scratch = gen_reg_rtx (Pmode); - seq = GEN_INT (alpha_next_sequence_number++); - - emit_insn (gen_movdi_er_tlsldm (r16, pic_offset_table_rtx, seq)); - insn = gen_call_value_osf_tlsldm (r0, tga, seq); - insn = emit_call_insn (insn); - CONST_OR_PURE_CALL_P (insn) = 1; - use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16); - - insn = get_insns (); - end_sequence (); - - eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), - UNSPEC_TLSLDM_CALL); - emit_libcall_block (insn, scratch, r0, eqv); - - eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL); - eqv = gen_rtx_CONST (Pmode, eqv); - - if (alpha_tls_size == 64) - { - dest = gen_reg_rtx (Pmode); - emit_insn (gen_rtx_SET (VOIDmode, dest, eqv)); - emit_insn (gen_adddi3 (dest, dest, scratch)); - return dest; - } - if (alpha_tls_size == 32) - { - insn = gen_rtx_HIGH (Pmode, eqv); - insn = gen_rtx_PLUS (Pmode, scratch, insn); - scratch = gen_reg_rtx (Pmode); - emit_insn (gen_rtx_SET (VOIDmode, scratch, insn)); - } - return gen_rtx_LO_SUM (Pmode, scratch, eqv); - - case TLS_MODEL_INITIAL_EXEC: - eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL); - eqv = gen_rtx_CONST (Pmode, eqv); - tp = gen_reg_rtx (Pmode); - scratch = gen_reg_rtx (Pmode); - dest = gen_reg_rtx (Pmode); - - emit_insn (gen_load_tp (tp)); - emit_insn (gen_rtx_SET (VOIDmode, scratch, eqv)); - emit_insn (gen_adddi3 (dest, tp, scratch)); - return dest; - - case TLS_MODEL_LOCAL_EXEC: - eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL); - eqv = gen_rtx_CONST (Pmode, eqv); - tp = gen_reg_rtx (Pmode); - - emit_insn (gen_load_tp (tp)); - if (alpha_tls_size == 32) - { - insn = gen_rtx_HIGH (Pmode, eqv); - insn = gen_rtx_PLUS (Pmode, tp, insn); - tp = gen_reg_rtx (Pmode); - emit_insn (gen_rtx_SET (VOIDmode, tp, insn)); - } - return gen_rtx_LO_SUM (Pmode, tp, eqv); - } - - if (local_symbolic_operand (x, Pmode)) - { - if (small_symbolic_operand (x, Pmode)) - return x; - else - { - if (!no_new_pseudos) - scratch = gen_reg_rtx (Pmode); - emit_insn (gen_rtx_SET (VOIDmode, scratch, - gen_rtx_HIGH (Pmode, x))); - return gen_rtx_LO_SUM (Pmode, scratch, x); - } - } - } - - return NULL; - - split_addend: - { - HOST_WIDE_INT low, high; - - low = ((addend & 0xffff) ^ 0x8000) - 0x8000; - addend -= low; - high = ((addend & 0xffffffff) ^ 0x80000000) - 0x80000000; - addend -= high; - - if (addend) - x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (addend), - (no_new_pseudos ? scratch : NULL_RTX), - 1, OPTAB_LIB_WIDEN); - if (high) - x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (high), - (no_new_pseudos ? scratch : NULL_RTX), - 1, OPTAB_LIB_WIDEN); - - return plus_constant (x, low); - } -} - -/* Primarily this is required for TLS symbols, but given that our move - patterns *ought* to be able to handle any symbol at any time, we - should never be spilling symbolic operands to the constant pool, ever. */ - -static bool -alpha_cannot_force_const_mem (rtx x) -{ - enum rtx_code code = GET_CODE (x); - return code == SYMBOL_REF || code == LABEL_REF || code == CONST; -} - -/* We do not allow indirect calls to be optimized into sibling calls, nor - can we allow a call to a function with a different GP to be optimized - into a sibcall. */ - -static bool -alpha_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) -{ - /* Can't do indirect tail calls, since we don't know if the target - uses the same GP. */ - if (!decl) - return false; - - /* Otherwise, we can make a tail call if the target function shares - the same GP. */ - return decl_has_samegp (decl); -} - -/* For TARGET_EXPLICIT_RELOCS, we don't obfuscate a SYMBOL_REF to a - small symbolic operand until after reload. At which point we need - to replace (mem (symbol_ref)) with (mem (lo_sum $29 symbol_ref)) - so that sched2 has the proper dependency information. */ - -static int -some_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED) -{ - rtx x = *px; - - /* Don't re-split. */ - if (GET_CODE (x) == LO_SUM) - return -1; - - return small_symbolic_operand (x, Pmode) != 0; -} - -int -some_small_symbolic_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED) -{ - return for_each_rtx (&x, some_small_symbolic_operand_1, NULL); -} - -static int -split_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED) -{ - rtx x = *px; - - /* Don't re-split. */ - if (GET_CODE (x) == LO_SUM) - return -1; - - if (small_symbolic_operand (x, Pmode)) - { - x = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x); - *px = x; - return -1; - } - - return 0; -} - -rtx -split_small_symbolic_operand (rtx x) -{ - x = copy_insn (x); - for_each_rtx (&x, split_small_symbolic_operand_1, NULL); - return x; -} - -/* Indicate that INSN cannot be duplicated. This is true for any insn - that we've marked with gpdisp relocs, since those have to stay in - 1-1 correspondence with one another. - - Technically we could copy them if we could set up a mapping from one - sequence number to another, across the set of insns to be duplicated. - This seems overly complicated and error-prone since interblock motion - from sched-ebb could move one of the pair of insns to a different block. - - Also cannot allow jsr insns to be duplicated. If they throw exceptions, - then they'll be in a different block from their ldgp. Which could lead - the bb reorder code to think that it would be ok to copy just the block - containing the call and branch to the block containing the ldgp. */ - -static bool -alpha_cannot_copy_insn_p (rtx insn) -{ - if (!reload_completed || !TARGET_EXPLICIT_RELOCS) - return false; - if (recog_memoized (insn) >= 0) - return get_attr_cannot_copy (insn); - else - return false; -} - - -/* Try a machine-dependent way of reloading an illegitimate address - operand. If we find one, push the reload and return the new rtx. */ - -rtx -alpha_legitimize_reload_address (rtx x, - enum machine_mode mode ATTRIBUTE_UNUSED, - int opnum, int type, - int ind_levels ATTRIBUTE_UNUSED) -{ - /* We must recognize output that we have already generated ourselves. */ - if (GET_CODE (x) == PLUS - && GET_CODE (XEXP (x, 0)) == PLUS - && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG - && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT - && GET_CODE (XEXP (x, 1)) == CONST_INT) - { - push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, - BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, - opnum, type); - return x; - } - - /* We wish to handle large displacements off a base register by - splitting the addend across an ldah and the mem insn. This - cuts number of extra insns needed from 3 to 1. */ - if (GET_CODE (x) == PLUS - && GET_CODE (XEXP (x, 0)) == REG - && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER - && REGNO_OK_FOR_BASE_P (REGNO (XEXP (x, 0))) - && GET_CODE (XEXP (x, 1)) == CONST_INT) - { - HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); - HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; - HOST_WIDE_INT high - = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000; - - /* Check for 32-bit overflow. */ - if (high + low != val) - return NULL_RTX; - - /* Reload the high part into a base reg; leave the low part - in the mem directly. */ - x = gen_rtx_PLUS (GET_MODE (x), - gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), - GEN_INT (high)), - GEN_INT (low)); - - push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, - BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, - opnum, type); - return x; - } - - return NULL_RTX; -} - -/* Compute a (partial) cost for rtx X. Return true if the complete - cost has been computed, and false if subexpressions should be - scanned. In either case, *TOTAL contains the cost result. */ - -static bool -alpha_rtx_costs (rtx x, int code, int outer_code, int *total) -{ - enum machine_mode mode = GET_MODE (x); - bool float_mode_p = FLOAT_MODE_P (mode); - - switch (code) - { - /* If this is an 8-bit constant, return zero since it can be used - nearly anywhere with no cost. If it is a valid operand for an - ADD or AND, likewise return 0 if we know it will be used in that - context. Otherwise, return 2 since it might be used there later. - All other constants take at least two insns. */ - case CONST_INT: - if (INTVAL (x) >= 0 && INTVAL (x) < 256) - { - *total = 0; - return true; - } - /* FALLTHRU */ - - case CONST_DOUBLE: - if (x == CONST0_RTX (mode)) - *total = 0; - else if ((outer_code == PLUS && add_operand (x, VOIDmode)) - || (outer_code == AND && and_operand (x, VOIDmode))) - *total = 0; - else if (add_operand (x, VOIDmode) || and_operand (x, VOIDmode)) - *total = 2; - else - *total = COSTS_N_INSNS (2); - return true; - - case CONST: - case SYMBOL_REF: - case LABEL_REF: - if (TARGET_EXPLICIT_RELOCS && small_symbolic_operand (x, VOIDmode)) - *total = COSTS_N_INSNS (outer_code != MEM); - else if (TARGET_EXPLICIT_RELOCS && local_symbolic_operand (x, VOIDmode)) - *total = COSTS_N_INSNS (1 + (outer_code != MEM)); - else if (tls_symbolic_operand_type (x)) - /* Estimate of cost for call_pal rduniq. */ - *total = COSTS_N_INSNS (15); - else - /* Otherwise we do a load from the GOT. */ - *total = COSTS_N_INSNS (alpha_memory_latency); - return true; - - case PLUS: - case MINUS: - if (float_mode_p) - *total = alpha_rtx_cost_data[alpha_cpu].fp_add; - else if (GET_CODE (XEXP (x, 0)) == MULT - && const48_operand (XEXP (XEXP (x, 0), 1), VOIDmode)) - { - *total = (rtx_cost (XEXP (XEXP (x, 0), 0), outer_code) - + rtx_cost (XEXP (x, 1), outer_code) + 2); - return true; - } - return false; - - case MULT: - if (float_mode_p) - *total = alpha_rtx_cost_data[alpha_cpu].fp_mult; - else if (mode == DImode) - *total = alpha_rtx_cost_data[alpha_cpu].int_mult_di; - else - *total = alpha_rtx_cost_data[alpha_cpu].int_mult_si; - return false; - - case ASHIFT: - if (GET_CODE (XEXP (x, 1)) == CONST_INT - && INTVAL (XEXP (x, 1)) <= 3) - { - *total = COSTS_N_INSNS (1); - return false; - } - /* FALLTHRU */ - - case ASHIFTRT: - case LSHIFTRT: - *total = alpha_rtx_cost_data[alpha_cpu].int_shift; - return false; - - case IF_THEN_ELSE: - if (float_mode_p) - *total = alpha_rtx_cost_data[alpha_cpu].fp_add; - else - *total = alpha_rtx_cost_data[alpha_cpu].int_cmov; - return false; - - case DIV: - case UDIV: - case MOD: - case UMOD: - if (!float_mode_p) - *total = COSTS_N_INSNS (70); /* ??? */ - else if (mode == SFmode) - *total = alpha_rtx_cost_data[alpha_cpu].fp_div_sf; - else - *total = alpha_rtx_cost_data[alpha_cpu].fp_div_df; - return false; - - case MEM: - *total = COSTS_N_INSNS (alpha_memory_latency); - return true; - - case NEG: - if (! float_mode_p) - { - *total = COSTS_N_INSNS (1); - return false; - } - /* FALLTHRU */ - - case ABS: - if (! float_mode_p) - { - *total = COSTS_N_INSNS (1) + alpha_rtx_cost_data[alpha_cpu].int_cmov; - return false; - } - /* FALLTHRU */ - - case FLOAT: - case UNSIGNED_FLOAT: - case FIX: - case UNSIGNED_FIX: - case FLOAT_EXTEND: - case FLOAT_TRUNCATE: - *total = alpha_rtx_cost_data[alpha_cpu].fp_add; - return false; - - default: - return false; - } -} - -/* REF is an alignable memory location. Place an aligned SImode - reference into *PALIGNED_MEM and the number of bits to shift into - *PBITNUM. SCRATCH is a free register for use in reloading out - of range stack slots. */ - -void -get_aligned_mem (rtx ref, rtx *paligned_mem, rtx *pbitnum) -{ - rtx base; - HOST_WIDE_INT offset = 0; - - if (GET_CODE (ref) != MEM) - abort (); - - if (reload_in_progress - && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0))) - { - base = find_replacement (&XEXP (ref, 0)); - - if (! memory_address_p (GET_MODE (ref), base)) - abort (); - } - else - { - base = XEXP (ref, 0); - } - - if (GET_CODE (base) == PLUS) - offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0); - - *paligned_mem - = widen_memory_access (ref, SImode, (offset & ~3) - offset); - - if (WORDS_BIG_ENDIAN) - *pbitnum = GEN_INT (32 - (GET_MODE_BITSIZE (GET_MODE (ref)) - + (offset & 3) * 8)); - else - *pbitnum = GEN_INT ((offset & 3) * 8); -} - -/* Similar, but just get the address. Handle the two reload cases. - Add EXTRA_OFFSET to the address we return. */ - -rtx -get_unaligned_address (rtx ref, int extra_offset) -{ - rtx base; - HOST_WIDE_INT offset = 0; - - if (GET_CODE (ref) != MEM) - abort (); - - if (reload_in_progress - && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0))) - { - base = find_replacement (&XEXP (ref, 0)); - - if (! memory_address_p (GET_MODE (ref), base)) - abort (); - } - else - { - base = XEXP (ref, 0); - } - - if (GET_CODE (base) == PLUS) - offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0); - - return plus_constant (base, offset + extra_offset); -} - -/* On the Alpha, all (non-symbolic) constants except zero go into - a floating-point register via memory. Note that we cannot - return anything that is not a subset of CLASS, and that some - symbolic constants cannot be dropped to memory. */ - -enum reg_class -alpha_preferred_reload_class(rtx x, enum reg_class class) -{ - /* Zero is present in any register class. */ - if (x == CONST0_RTX (GET_MODE (x))) - return class; - - /* These sorts of constants we can easily drop to memory. */ - if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) - { - if (class == FLOAT_REGS) - return NO_REGS; - if (class == ALL_REGS) - return GENERAL_REGS; - return class; - } - - /* All other kinds of constants should not (and in the case of HIGH - cannot) be dropped to memory -- instead we use a GENERAL_REGS - secondary reload. */ - if (CONSTANT_P (x)) - return (class == ALL_REGS ? GENERAL_REGS : class); - - return class; -} - -/* Loading and storing HImode or QImode values to and from memory - usually requires a scratch register. The exceptions are loading - QImode and HImode from an aligned address to a general register - unless byte instructions are permitted. - - We also cannot load an unaligned address or a paradoxical SUBREG - into an FP register. - - We also cannot do integral arithmetic into FP regs, as might result - from register elimination into a DImode fp register. */ - -enum reg_class -secondary_reload_class (enum reg_class class, enum machine_mode mode, - rtx x, int in) -{ - if ((mode == QImode || mode == HImode) && ! TARGET_BWX) - { - if (GET_CODE (x) == MEM - || (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER) - || (GET_CODE (x) == SUBREG - && (GET_CODE (SUBREG_REG (x)) == MEM - || (GET_CODE (SUBREG_REG (x)) == REG - && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)))) - { - if (!in || !aligned_memory_operand(x, mode)) - return GENERAL_REGS; - } - } - - if (class == FLOAT_REGS) - { - if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND) - return GENERAL_REGS; - - if (GET_CODE (x) == SUBREG - && (GET_MODE_SIZE (GET_MODE (x)) - > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) - return GENERAL_REGS; - - if (in && INTEGRAL_MODE_P (mode) - && ! (memory_operand (x, mode) || x == const0_rtx)) - return GENERAL_REGS; - } - - return NO_REGS; -} - -/* Subfunction of the following function. Update the flags of any MEM - found in part of X. */ - -static void -alpha_set_memflags_1 (rtx x, int in_struct_p, int volatile_p, int unchanging_p) -{ - int i; - - switch (GET_CODE (x)) - { - case SEQUENCE: - abort (); - - case PARALLEL: - for (i = XVECLEN (x, 0) - 1; i >= 0; i--) - alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p, - unchanging_p); - break; - - case INSN: - alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p, - unchanging_p); - break; - - case SET: - alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p, - unchanging_p); - alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p, - unchanging_p); - break; - - case MEM: - MEM_IN_STRUCT_P (x) = in_struct_p; - MEM_VOLATILE_P (x) = volatile_p; - RTX_UNCHANGING_P (x) = unchanging_p; - /* Sadly, we cannot use alias sets because the extra aliasing - produced by the AND interferes. Given that two-byte quantities - are the only thing we would be able to differentiate anyway, - there does not seem to be any point in convoluting the early - out of the alias check. */ - break; - - default: - break; - } -} - -/* Given INSN, which is an INSN list or the PATTERN of a single insn - generated to perform a memory operation, look for any MEMs in either - a SET_DEST or a SET_SRC and copy the in-struct, unchanging, and - volatile flags from REF into each of the MEMs found. If REF is not - a MEM, don't do anything. */ - -void -alpha_set_memflags (rtx insn, rtx ref) -{ - int in_struct_p, volatile_p, unchanging_p; - - if (GET_CODE (ref) != MEM) - return; - - in_struct_p = MEM_IN_STRUCT_P (ref); - volatile_p = MEM_VOLATILE_P (ref); - unchanging_p = RTX_UNCHANGING_P (ref); - - /* This is only called from alpha.md, after having had something - generated from one of the insn patterns. So if everything is - zero, the pattern is already up-to-date. */ - if (! in_struct_p && ! volatile_p && ! unchanging_p) - return; - - alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p); -} - -/* Internal routine for alpha_emit_set_const to check for N or below insns. */ - -static rtx -alpha_emit_set_const_1 (rtx target, enum machine_mode mode, - HOST_WIDE_INT c, int n) -{ - HOST_WIDE_INT new; - int i, bits; - /* Use a pseudo if highly optimizing and still generating RTL. */ - rtx subtarget - = (flag_expensive_optimizations && !no_new_pseudos ? 0 : target); - rtx temp, insn; - - /* If this is a sign-extended 32-bit constant, we can do this in at most - three insns, so do it if we have enough insns left. We always have - a sign-extended 32-bit constant when compiling on a narrow machine. */ - - if (HOST_BITS_PER_WIDE_INT != 64 - || c >> 31 == -1 || c >> 31 == 0) - { - HOST_WIDE_INT low = ((c & 0xffff) ^ 0x8000) - 0x8000; - HOST_WIDE_INT tmp1 = c - low; - HOST_WIDE_INT high = (((tmp1 >> 16) & 0xffff) ^ 0x8000) - 0x8000; - HOST_WIDE_INT extra = 0; - - /* If HIGH will be interpreted as negative but the constant is - positive, we must adjust it to do two ldha insns. */ - - if ((high & 0x8000) != 0 && c >= 0) - { - extra = 0x4000; - tmp1 -= 0x40000000; - high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000); - } - - if (c == low || (low == 0 && extra == 0)) - { - /* We used to use copy_to_suggested_reg (GEN_INT (c), target, mode) - but that meant that we can't handle INT_MIN on 32-bit machines - (like NT/Alpha), because we recurse indefinitely through - emit_move_insn to gen_movdi. So instead, since we know exactly - what we want, create it explicitly. */ - - if (target == NULL) - target = gen_reg_rtx (mode); - emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (c))); - return target; - } - else if (n >= 2 + (extra != 0)) - { - if (no_new_pseudos) - { - emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (high << 16))); - temp = target; - } - else - temp = copy_to_suggested_reg (GEN_INT (high << 16), - subtarget, mode); - - /* As of 2002-02-23, addsi3 is only available when not optimizing. - This means that if we go through expand_binop, we'll try to - generate extensions, etc, which will require new pseudos, which - will fail during some split phases. The SImode add patterns - still exist, but are not named. So build the insns by hand. */ - - if (extra != 0) - { - if (! subtarget) - subtarget = gen_reg_rtx (mode); - insn = gen_rtx_PLUS (mode, temp, GEN_INT (extra << 16)); - insn = gen_rtx_SET (VOIDmode, subtarget, insn); - emit_insn (insn); - temp = subtarget; - } - - if (target == NULL) - target = gen_reg_rtx (mode); - insn = gen_rtx_PLUS (mode, temp, GEN_INT (low)); - insn = gen_rtx_SET (VOIDmode, target, insn); - emit_insn (insn); - return target; - } - } - - /* If we couldn't do it that way, try some other methods. But if we have - no instructions left, don't bother. Likewise, if this is SImode and - we can't make pseudos, we can't do anything since the expand_binop - and expand_unop calls will widen and try to make pseudos. */ - - if (n == 1 || (mode == SImode && no_new_pseudos)) - return 0; - - /* Next, see if we can load a related constant and then shift and possibly - negate it to get the constant we want. Try this once each increasing - numbers of insns. */ - - for (i = 1; i < n; i++) - { - /* First, see if minus some low bits, we've an easy load of - high bits. */ - - new = ((c & 0xffff) ^ 0x8000) - 0x8000; - if (new != 0 - && (temp = alpha_emit_set_const (subtarget, mode, c - new, i)) != 0) - return expand_binop (mode, add_optab, temp, GEN_INT (new), - target, 0, OPTAB_WIDEN); - - /* Next try complementing. */ - if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0) - return expand_unop (mode, one_cmpl_optab, temp, target, 0); - - /* Next try to form a constant and do a left shift. We can do this - if some low-order bits are zero; the exact_log2 call below tells - us that information. The bits we are shifting out could be any - value, but here we'll just try the 0- and sign-extended forms of - the constant. To try to increase the chance of having the same - constant in more than one insn, start at the highest number of - bits to shift, but try all possibilities in case a ZAPNOT will - be useful. */ - - if ((bits = exact_log2 (c & - c)) > 0) - for (; bits > 0; bits--) - if ((temp = (alpha_emit_set_const - (subtarget, mode, c >> bits, i))) != 0 - || ((temp = (alpha_emit_set_const - (subtarget, mode, - ((unsigned HOST_WIDE_INT) c) >> bits, i))) - != 0)) - return expand_binop (mode, ashl_optab, temp, GEN_INT (bits), - target, 0, OPTAB_WIDEN); - - /* Now try high-order zero bits. Here we try the shifted-in bits as - all zero and all ones. Be careful to avoid shifting outside the - mode and to avoid shifting outside the host wide int size. */ - /* On narrow hosts, don't shift a 1 into the high bit, since we'll - confuse the recursive call and set all of the high 32 bits. */ - - if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8) - - floor_log2 (c) - 1 - (HOST_BITS_PER_WIDE_INT < 64))) > 0) - for (; bits > 0; bits--) - if ((temp = alpha_emit_set_const (subtarget, mode, - c << bits, i)) != 0 - || ((temp = (alpha_emit_set_const - (subtarget, mode, - ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)), - i))) - != 0)) - return expand_binop (mode, lshr_optab, temp, GEN_INT (bits), - target, 1, OPTAB_WIDEN); - - /* Now try high-order 1 bits. We get that with a sign-extension. - But one bit isn't enough here. Be careful to avoid shifting outside - the mode and to avoid shifting outside the host wide int size. */ - - if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8) - - floor_log2 (~ c) - 2)) > 0) - for (; bits > 0; bits--) - if ((temp = alpha_emit_set_const (subtarget, mode, - c << bits, i)) != 0 - || ((temp = (alpha_emit_set_const - (subtarget, mode, - ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)), - i))) - != 0)) - return expand_binop (mode, ashr_optab, temp, GEN_INT (bits), - target, 0, OPTAB_WIDEN); - } - -#if HOST_BITS_PER_WIDE_INT == 64 - /* Finally, see if can load a value into the target that is the same as the - constant except that all bytes that are 0 are changed to be 0xff. If we - can, then we can do a ZAPNOT to obtain the desired constant. */ - - new = c; - for (i = 0; i < 64; i += 8) - if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0) - new |= (HOST_WIDE_INT) 0xff << i; - - /* We are only called for SImode and DImode. If this is SImode, ensure that - we are sign extended to a full word. */ - - if (mode == SImode) - new = ((new & 0xffffffff) ^ 0x80000000) - 0x80000000; - - if (new != c && new != -1 - && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0) - return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new), - target, 0, OPTAB_WIDEN); -#endif - - return 0; -} - -/* Try to output insns to set TARGET equal to the constant C if it can be - done in less than N insns. Do all computations in MODE. Returns the place - where the output has been placed if it can be done and the insns have been - emitted. If it would take more than N insns, zero is returned and no - insns and emitted. */ - -rtx -alpha_emit_set_const (rtx target, enum machine_mode mode, - HOST_WIDE_INT c, int n) -{ - rtx result = 0; - rtx orig_target = target; - int i; - - /* If we can't make any pseudos, TARGET is an SImode hard register, we - can't load this constant in one insn, do this in DImode. */ - if (no_new_pseudos && mode == SImode - && GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER - && (result = alpha_emit_set_const_1 (target, mode, c, 1)) == 0) - { - target = gen_lowpart (DImode, target); - mode = DImode; - } - - /* Try 1 insn, then 2, then up to N. */ - for (i = 1; i <= n; i++) - { - result = alpha_emit_set_const_1 (target, mode, c, i); - if (result) - { - rtx insn = get_last_insn (); - rtx set = single_set (insn); - if (! CONSTANT_P (SET_SRC (set))) - set_unique_reg_note (get_last_insn (), REG_EQUAL, GEN_INT (c)); - break; - } - } - - /* Allow for the case where we changed the mode of TARGET. */ - if (result == target) - result = orig_target; - - return result; -} - -/* Having failed to find a 3 insn sequence in alpha_emit_set_const, - fall back to a straight forward decomposition. We do this to avoid - exponential run times encountered when looking for longer sequences - with alpha_emit_set_const. */ - -rtx -alpha_emit_set_long_const (rtx target, HOST_WIDE_INT c1, HOST_WIDE_INT c2) -{ - HOST_WIDE_INT d1, d2, d3, d4; - - /* Decompose the entire word */ -#if HOST_BITS_PER_WIDE_INT >= 64 - if (c2 != -(c1 < 0)) - abort (); - d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000; - c1 -= d1; - d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000; - c1 = (c1 - d2) >> 32; - d3 = ((c1 & 0xffff) ^ 0x8000) - 0x8000; - c1 -= d3; - d4 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000; - if (c1 != d4) - abort (); -#else - d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000; - c1 -= d1; - d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000; - if (c1 != d2) - abort (); - c2 += (d2 < 0); - d3 = ((c2 & 0xffff) ^ 0x8000) - 0x8000; - c2 -= d3; - d4 = ((c2 & 0xffffffff) ^ 0x80000000) - 0x80000000; - if (c2 != d4) - abort (); -#endif - - /* Construct the high word */ - if (d4) - { - emit_move_insn (target, GEN_INT (d4)); - if (d3) - emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d3))); - } - else - emit_move_insn (target, GEN_INT (d3)); - - /* Shift it into place */ - emit_move_insn (target, gen_rtx_ASHIFT (DImode, target, GEN_INT (32))); - - /* Add in the low bits. */ - if (d2) - emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d2))); - if (d1) - emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d1))); - - return target; -} - -/* Expand a move instruction; return true if all work is done. - We don't handle non-bwx subword loads here. */ - -bool -alpha_expand_mov (enum machine_mode mode, rtx *operands) -{ - /* If the output is not a register, the input must be. */ - if (GET_CODE (operands[0]) == MEM - && ! reg_or_0_operand (operands[1], mode)) - operands[1] = force_reg (mode, operands[1]); - - /* Allow legitimize_address to perform some simplifications. */ - if (mode == Pmode && symbolic_operand (operands[1], mode)) - { - rtx tmp; - - /* With RTL inlining, at -O3, rtl is generated, stored, then actually - compiled at the end of compilation. In the meantime, someone can - re-encode-section-info on some symbol changing it e.g. from global - to local-not-small. If this happens, we'd have emitted a plain - load rather than a high+losum load and not recognize the insn. - - So if rtl inlining is in effect, we delay the global/not-global - decision until rest_of_compilation by wrapping it in an - UNSPEC_SYMBOL. */ - if (TARGET_EXPLICIT_RELOCS && flag_inline_functions - && rtx_equal_function_value_matters - && global_symbolic_operand (operands[1], mode)) - { - emit_insn (gen_movdi_er_maybe_g (operands[0], operands[1])); - return true; - } - - tmp = alpha_legitimize_address (operands[1], operands[0], mode); - if (tmp) - { - if (tmp == operands[0]) - return true; - operands[1] = tmp; - return false; - } - } - - /* Early out for non-constants and valid constants. */ - if (! CONSTANT_P (operands[1]) || input_operand (operands[1], mode)) - return false; - - /* Split large integers. */ - if (GET_CODE (operands[1]) == CONST_INT - || GET_CODE (operands[1]) == CONST_DOUBLE) - { - HOST_WIDE_INT i0, i1; - rtx temp = NULL_RTX; - - if (GET_CODE (operands[1]) == CONST_INT) - { - i0 = INTVAL (operands[1]); - i1 = -(i0 < 0); - } - else if (HOST_BITS_PER_WIDE_INT >= 64) - { - i0 = CONST_DOUBLE_LOW (operands[1]); - i1 = -(i0 < 0); - } - else - { - i0 = CONST_DOUBLE_LOW (operands[1]); - i1 = CONST_DOUBLE_HIGH (operands[1]); - } - - if (HOST_BITS_PER_WIDE_INT >= 64 || i1 == -(i0 < 0)) - temp = alpha_emit_set_const (operands[0], mode, i0, 3); - - if (!temp && TARGET_BUILD_CONSTANTS) - temp = alpha_emit_set_long_const (operands[0], i0, i1); - - if (temp) - { - if (rtx_equal_p (operands[0], temp)) - return true; - operands[1] = temp; - return false; - } - } - - /* Otherwise we've nothing left but to drop the thing to memory. */ - operands[1] = force_const_mem (mode, operands[1]); - if (reload_in_progress) - { - emit_move_insn (operands[0], XEXP (operands[1], 0)); - operands[1] = copy_rtx (operands[1]); - XEXP (operands[1], 0) = operands[0]; - } - else - operands[1] = validize_mem (operands[1]); - return false; -} - -/* Expand a non-bwx QImode or HImode move instruction; - return true if all work is done. */ - -bool -alpha_expand_mov_nobwx (enum machine_mode mode, rtx *operands) -{ - /* If the output is not a register, the input must be. */ - if (GET_CODE (operands[0]) == MEM) - operands[1] = force_reg (mode, operands[1]); - - /* Handle four memory cases, unaligned and aligned for either the input - or the output. The only case where we can be called during reload is - for aligned loads; all other cases require temporaries. */ - - if (GET_CODE (operands[1]) == MEM - || (GET_CODE (operands[1]) == SUBREG - && GET_CODE (SUBREG_REG (operands[1])) == MEM) - || (reload_in_progress && GET_CODE (operands[1]) == REG - && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER) - || (reload_in_progress && GET_CODE (operands[1]) == SUBREG - && GET_CODE (SUBREG_REG (operands[1])) == REG - && REGNO (SUBREG_REG (operands[1])) >= FIRST_PSEUDO_REGISTER)) - { - if (aligned_memory_operand (operands[1], mode)) - { - if (reload_in_progress) - { - emit_insn ((mode == QImode - ? gen_reload_inqi_help - : gen_reload_inhi_help) - (operands[0], operands[1], - gen_rtx_REG (SImode, REGNO (operands[0])))); - } - else - { - rtx aligned_mem, bitnum; - rtx scratch = gen_reg_rtx (SImode); - rtx subtarget; - bool copyout; - - get_aligned_mem (operands[1], &aligned_mem, &bitnum); - - subtarget = operands[0]; - if (GET_CODE (subtarget) == REG) - subtarget = gen_lowpart (DImode, subtarget), copyout = false; - else - subtarget = gen_reg_rtx (DImode), copyout = true; - - emit_insn ((mode == QImode - ? gen_aligned_loadqi - : gen_aligned_loadhi) - (subtarget, aligned_mem, bitnum, scratch)); - - if (copyout) - emit_move_insn (operands[0], gen_lowpart (mode, subtarget)); - } - } - else - { - /* Don't pass these as parameters since that makes the generated - code depend on parameter evaluation order which will cause - bootstrap failures. */ - - rtx temp1, temp2, seq, subtarget; - bool copyout; - - temp1 = gen_reg_rtx (DImode); - temp2 = gen_reg_rtx (DImode); - - subtarget = operands[0]; - if (GET_CODE (subtarget) == REG) - subtarget = gen_lowpart (DImode, subtarget), copyout = false; - else - subtarget = gen_reg_rtx (DImode), copyout = true; - - seq = ((mode == QImode - ? gen_unaligned_loadqi - : gen_unaligned_loadhi) - (subtarget, get_unaligned_address (operands[1], 0), - temp1, temp2)); - alpha_set_memflags (seq, operands[1]); - emit_insn (seq); - - if (copyout) - emit_move_insn (operands[0], gen_lowpart (mode, subtarget)); - } - return true; - } - - if (GET_CODE (operands[0]) == MEM - || (GET_CODE (operands[0]) == SUBREG - && GET_CODE (SUBREG_REG (operands[0])) == MEM) - || (reload_in_progress && GET_CODE (operands[0]) == REG - && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER) - || (reload_in_progress && GET_CODE (operands[0]) == SUBREG - && GET_CODE (SUBREG_REG (operands[0])) == REG - && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)) - { - if (aligned_memory_operand (operands[0], mode)) - { - rtx aligned_mem, bitnum; - rtx temp1 = gen_reg_rtx (SImode); - rtx temp2 = gen_reg_rtx (SImode); - - get_aligned_mem (operands[0], &aligned_mem, &bitnum); - - emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum, - temp1, temp2)); - } - else - { - rtx temp1 = gen_reg_rtx (DImode); - rtx temp2 = gen_reg_rtx (DImode); - rtx temp3 = gen_reg_rtx (DImode); - rtx seq = ((mode == QImode - ? gen_unaligned_storeqi - : gen_unaligned_storehi) - (get_unaligned_address (operands[0], 0), - operands[1], temp1, temp2, temp3)); - - alpha_set_memflags (seq, operands[0]); - emit_insn (seq); - } - return true; - } - - return false; -} - -/* Generate an unsigned DImode to FP conversion. This is the same code - optabs would emit if we didn't have TFmode patterns. - - For SFmode, this is the only construction I've found that can pass - gcc.c-torture/execute/ieee/rbug.c. No scenario that uses DFmode - intermediates will work, because you'll get intermediate rounding - that ruins the end result. Some of this could be fixed by turning - on round-to-positive-infinity, but that requires diddling the fpsr, - which kills performance. I tried turning this around and converting - to a negative number, so that I could turn on /m, but either I did - it wrong or there's something else cause I wound up with the exact - same single-bit error. There is a branch-less form of this same code: - - srl $16,1,$1 - and $16,1,$2 - cmplt $16,0,$3 - or $1,$2,$2 - cmovge $16,$16,$2 - itoft $3,$f10 - itoft $2,$f11 - cvtqs $f11,$f11 - adds $f11,$f11,$f0 - fcmoveq $f10,$f11,$f0 - - I'm not using it because it's the same number of instructions as - this branch-full form, and it has more serialized long latency - instructions on the critical path. - - For DFmode, we can avoid rounding errors by breaking up the word - into two pieces, converting them separately, and adding them back: - - LC0: .long 0,0x5f800000 - - itoft $16,$f11 - lda $2,LC0 - cmplt $16,0,$1 - cpyse $f11,$f31,$f10 - cpyse $f31,$f11,$f11 - s4addq $1,$2,$1 - lds $f12,0($1) - cvtqt $f10,$f10 - cvtqt $f11,$f11 - addt $f12,$f10,$f0 - addt $f0,$f11,$f0 - - This doesn't seem to be a clear-cut win over the optabs form. - It probably all depends on the distribution of numbers being - converted -- in the optabs form, all but high-bit-set has a - much lower minimum execution time. */ - -void -alpha_emit_floatuns (rtx operands[2]) -{ - rtx neglab, donelab, i0, i1, f0, in, out; - enum machine_mode mode; - - out = operands[0]; - in = force_reg (DImode, operands[1]); - mode = GET_MODE (out); - neglab = gen_label_rtx (); - donelab = gen_label_rtx (); - i0 = gen_reg_rtx (DImode); - i1 = gen_reg_rtx (DImode); - f0 = gen_reg_rtx (mode); - - emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab); - - emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in))); - emit_jump_insn (gen_jump (donelab)); - emit_barrier (); - - emit_label (neglab); - - emit_insn (gen_lshrdi3 (i0, in, const1_rtx)); - emit_insn (gen_anddi3 (i1, in, const1_rtx)); - emit_insn (gen_iordi3 (i0, i0, i1)); - emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0))); - emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0))); - - emit_label (donelab); -} - -/* Generate the comparison for a conditional branch. */ - -rtx -alpha_emit_conditional_branch (enum rtx_code code) -{ - enum rtx_code cmp_code, branch_code; - enum machine_mode cmp_mode, branch_mode = VOIDmode; - rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1; - rtx tem; - - if (alpha_compare.fp_p && GET_MODE (op0) == TFmode) - { - if (! TARGET_HAS_XFLOATING_LIBS) - abort (); - - /* X_floating library comparison functions return - -1 unordered - 0 false - 1 true - Convert the compare against the raw return value. */ - - switch (code) - { - case UNORDERED: - cmp_code = EQ; - code = LT; - break; - case ORDERED: - cmp_code = EQ; - code = GE; - break; - case NE: - cmp_code = NE; - code = NE; - break; - default: - cmp_code = code; - code = GT; - break; - } - - op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1); - op1 = const0_rtx; - alpha_compare.fp_p = 0; - } - - /* The general case: fold the comparison code to the types of compares - that we have, choosing the branch as necessary. */ - switch (code) - { - case EQ: case LE: case LT: case LEU: case LTU: - case UNORDERED: - /* We have these compares: */ - cmp_code = code, branch_code = NE; - break; - - case NE: - case ORDERED: - /* These must be reversed. */ - cmp_code = reverse_condition (code), branch_code = EQ; - break; - - case GE: case GT: case GEU: case GTU: - /* For FP, we swap them, for INT, we reverse them. */ - if (alpha_compare.fp_p) - { - cmp_code = swap_condition (code); - branch_code = NE; - tem = op0, op0 = op1, op1 = tem; - } - else - { - cmp_code = reverse_condition (code); - branch_code = EQ; - } - break; - - default: - abort (); - } - - if (alpha_compare.fp_p) - { - cmp_mode = DFmode; - if (flag_unsafe_math_optimizations) - { - /* When we are not as concerned about non-finite values, and we - are comparing against zero, we can branch directly. */ - if (op1 == CONST0_RTX (DFmode)) - cmp_code = NIL, branch_code = code; - else if (op0 == CONST0_RTX (DFmode)) - { - /* Undo the swap we probably did just above. */ - tem = op0, op0 = op1, op1 = tem; - branch_code = swap_condition (cmp_code); - cmp_code = NIL; - } - } - else - { - /* ??? We mark the branch mode to be CCmode to prevent the - compare and branch from being combined, since the compare - insn follows IEEE rules that the branch does not. */ - branch_mode = CCmode; - } - } - else - { - cmp_mode = DImode; - - /* The following optimizations are only for signed compares. */ - if (code != LEU && code != LTU && code != GEU && code != GTU) - { - /* Whee. Compare and branch against 0 directly. */ - if (op1 == const0_rtx) - cmp_code = NIL, branch_code = code; - - /* If the constants doesn't fit into an immediate, but can - be generated by lda/ldah, we adjust the argument and - compare against zero, so we can use beq/bne directly. */ - /* ??? Don't do this when comparing against symbols, otherwise - we'll reduce (&x == 0x1234) to (&x-0x1234 == 0), which will - be declared false out of hand (at least for non-weak). */ - else if (GET_CODE (op1) == CONST_INT - && (code == EQ || code == NE) - && !(symbolic_operand (op0, VOIDmode) - || (GET_CODE (op0) == REG && REG_POINTER (op0)))) - { - HOST_WIDE_INT v = INTVAL (op1), n = -v; - - if (! CONST_OK_FOR_LETTER_P (v, 'I') - && (CONST_OK_FOR_LETTER_P (n, 'K') - || CONST_OK_FOR_LETTER_P (n, 'L'))) - { - cmp_code = PLUS, branch_code = code; - op1 = GEN_INT (n); - } - } - } - - if (!reg_or_0_operand (op0, DImode)) - op0 = force_reg (DImode, op0); - if (cmp_code != PLUS && !reg_or_8bit_operand (op1, DImode)) - op1 = force_reg (DImode, op1); - } - - /* Emit an initial compare instruction, if necessary. */ - tem = op0; - if (cmp_code != NIL) - { - tem = gen_reg_rtx (cmp_mode); - emit_move_insn (tem, gen_rtx_fmt_ee (cmp_code, cmp_mode, op0, op1)); - } - - /* Zero the operands. */ - memset (&alpha_compare, 0, sizeof (alpha_compare)); - - /* Return the branch comparison. */ - return gen_rtx_fmt_ee (branch_code, branch_mode, tem, CONST0_RTX (cmp_mode)); -} - -/* Certain simplifications can be done to make invalid setcc operations - valid. Return the final comparison, or NULL if we can't work. */ - -rtx -alpha_emit_setcc (enum rtx_code code) -{ - enum rtx_code cmp_code; - rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1; - int fp_p = alpha_compare.fp_p; - rtx tmp; - - /* Zero the operands. */ - memset (&alpha_compare, 0, sizeof (alpha_compare)); - - if (fp_p && GET_MODE (op0) == TFmode) - { - if (! TARGET_HAS_XFLOATING_LIBS) - abort (); - - /* X_floating library comparison functions return - -1 unordered - 0 false - 1 true - Convert the compare against the raw return value. */ - - if (code == UNORDERED || code == ORDERED) - cmp_code = EQ; - else - cmp_code = code; - - op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1); - op1 = const0_rtx; - fp_p = 0; - - if (code == UNORDERED) - code = LT; - else if (code == ORDERED) - code = GE; - else - code = GT; - } - - if (fp_p && !TARGET_FIX) - return NULL_RTX; - - /* The general case: fold the comparison code to the types of compares - that we have, choosing the branch as necessary. */ - - cmp_code = NIL; - switch (code) - { - case EQ: case LE: case LT: case LEU: case LTU: - case UNORDERED: - /* We have these compares. */ - if (fp_p) - cmp_code = code, code = NE; - break; - - case NE: - if (!fp_p && op1 == const0_rtx) - break; - /* FALLTHRU */ - - case ORDERED: - cmp_code = reverse_condition (code); - code = EQ; - break; - - case GE: case GT: case GEU: case GTU: - /* These normally need swapping, but for integer zero we have - special patterns that recognize swapped operands. */ - if (!fp_p && op1 == const0_rtx) - break; - code = swap_condition (code); - if (fp_p) - cmp_code = code, code = NE; - tmp = op0, op0 = op1, op1 = tmp; - break; - - default: - abort (); - } - - if (!fp_p) - { - if (!register_operand (op0, DImode)) - op0 = force_reg (DImode, op0); - if (!reg_or_8bit_operand (op1, DImode)) - op1 = force_reg (DImode, op1); - } - - /* Emit an initial compare instruction, if necessary. */ - if (cmp_code != NIL) - { - enum machine_mode mode = fp_p ? DFmode : DImode; - - tmp = gen_reg_rtx (mode); - emit_insn (gen_rtx_SET (VOIDmode, tmp, - gen_rtx_fmt_ee (cmp_code, mode, op0, op1))); - - op0 = fp_p ? gen_lowpart (DImode, tmp) : tmp; - op1 = const0_rtx; - } - - /* Return the setcc comparison. */ - return gen_rtx_fmt_ee (code, DImode, op0, op1); -} - - -/* Rewrite a comparison against zero CMP of the form - (CODE (cc0) (const_int 0)) so it can be written validly in - a conditional move (if_then_else CMP ...). - If both of the operands that set cc0 are nonzero we must emit - an insn to perform the compare (it can't be done within - the conditional move). */ - -rtx -alpha_emit_conditional_move (rtx cmp, enum machine_mode mode) -{ - enum rtx_code code = GET_CODE (cmp); - enum rtx_code cmov_code = NE; - rtx op0 = alpha_compare.op0; - rtx op1 = alpha_compare.op1; - int fp_p = alpha_compare.fp_p; - enum machine_mode cmp_mode - = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0)); - enum machine_mode cmp_op_mode = fp_p ? DFmode : DImode; - enum machine_mode cmov_mode = VOIDmode; - int local_fast_math = flag_unsafe_math_optimizations; - rtx tem; - - /* Zero the operands. */ - memset (&alpha_compare, 0, sizeof (alpha_compare)); - - if (fp_p != FLOAT_MODE_P (mode)) - { - enum rtx_code cmp_code; - - if (! TARGET_FIX) - return 0; - - /* If we have fp<->int register move instructions, do a cmov by - performing the comparison in fp registers, and move the - zero/nonzero value to integer registers, where we can then - use a normal cmov, or vice-versa. */ - - switch (code) - { - case EQ: case LE: case LT: case LEU: case LTU: - /* We have these compares. */ - cmp_code = code, code = NE; - break; - - case NE: - /* This must be reversed. */ - cmp_code = EQ, code = EQ; - break; - - case GE: case GT: case GEU: case GTU: - /* These normally need swapping, but for integer zero we have - special patterns that recognize swapped operands. */ - if (!fp_p && op1 == const0_rtx) - cmp_code = code, code = NE; - else - { - cmp_code = swap_condition (code); - code = NE; - tem = op0, op0 = op1, op1 = tem; - } - break; - - default: - abort (); - } - - tem = gen_reg_rtx (cmp_op_mode); - emit_insn (gen_rtx_SET (VOIDmode, tem, - gen_rtx_fmt_ee (cmp_code, cmp_op_mode, - op0, op1))); - - cmp_mode = cmp_op_mode = fp_p ? DImode : DFmode; - op0 = gen_lowpart (cmp_op_mode, tem); - op1 = CONST0_RTX (cmp_op_mode); - fp_p = !fp_p; - local_fast_math = 1; - } - - /* We may be able to use a conditional move directly. - This avoids emitting spurious compares. */ - if (signed_comparison_operator (cmp, VOIDmode) - && (!fp_p || local_fast_math) - && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode))) - return gen_rtx_fmt_ee (code, VOIDmode, op0, op1); - - /* We can't put the comparison inside the conditional move; - emit a compare instruction and put that inside the - conditional move. Make sure we emit only comparisons we have; - swap or reverse as necessary. */ - - if (no_new_pseudos) - return NULL_RTX; - - switch (code) - { - case EQ: case LE: case LT: case LEU: case LTU: - /* We have these compares: */ - break; - - case NE: - /* This must be reversed. */ - code = reverse_condition (code); - cmov_code = EQ; - break; - - case GE: case GT: case GEU: case GTU: - /* These must be swapped. */ - if (op1 != CONST0_RTX (cmp_mode)) - { - code = swap_condition (code); - tem = op0, op0 = op1, op1 = tem; - } - break; - - default: - abort (); - } - - if (!fp_p) - { - if (!reg_or_0_operand (op0, DImode)) - op0 = force_reg (DImode, op0); - if (!reg_or_8bit_operand (op1, DImode)) - op1 = force_reg (DImode, op1); - } - - /* ??? We mark the branch mode to be CCmode to prevent the compare - and cmov from being combined, since the compare insn follows IEEE - rules that the cmov does not. */ - if (fp_p && !local_fast_math) - cmov_mode = CCmode; - - tem = gen_reg_rtx (cmp_op_mode); - emit_move_insn (tem, gen_rtx_fmt_ee (code, cmp_op_mode, op0, op1)); - return gen_rtx_fmt_ee (cmov_code, cmov_mode, tem, CONST0_RTX (cmp_op_mode)); -} - -/* Simplify a conditional move of two constants into a setcc with - arithmetic. This is done with a splitter since combine would - just undo the work if done during code generation. It also catches - cases we wouldn't have before cse. */ - -int -alpha_split_conditional_move (enum rtx_code code, rtx dest, rtx cond, - rtx t_rtx, rtx f_rtx) -{ - HOST_WIDE_INT t, f, diff; - enum machine_mode mode; - rtx target, subtarget, tmp; - - mode = GET_MODE (dest); - t = INTVAL (t_rtx); - f = INTVAL (f_rtx); - diff = t - f; - - if (((code == NE || code == EQ) && diff < 0) - || (code == GE || code == GT)) - { - code = reverse_condition (code); - diff = t, t = f, f = diff; - diff = t - f; - } - - subtarget = target = dest; - if (mode != DImode) - { - target = gen_lowpart (DImode, dest); - if (! no_new_pseudos) - subtarget = gen_reg_rtx (DImode); - else - subtarget = target; - } - /* Below, we must be careful to use copy_rtx on target and subtarget - in intermediate insns, as they may be a subreg rtx, which may not - be shared. */ - - if (f == 0 && exact_log2 (diff) > 0 - /* On EV6, we've got enough shifters to make non-arithmetic shifts - viable over a longer latency cmove. On EV5, the E0 slot is a - scarce resource, and on EV4 shift has the same latency as a cmove. */ - && (diff <= 8 || alpha_cpu == PROCESSOR_EV6)) - { - tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx); - emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp)); - - tmp = gen_rtx_ASHIFT (DImode, copy_rtx (subtarget), - GEN_INT (exact_log2 (t))); - emit_insn (gen_rtx_SET (VOIDmode, target, tmp)); - } - else if (f == 0 && t == -1) - { - tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx); - emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp)); - - emit_insn (gen_negdi2 (target, copy_rtx (subtarget))); - } - else if (diff == 1 || diff == 4 || diff == 8) - { - rtx add_op; - - tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx); - emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp)); - - if (diff == 1) - emit_insn (gen_adddi3 (target, copy_rtx (subtarget), GEN_INT (f))); - else - { - add_op = GEN_INT (f); - if (sext_add_operand (add_op, mode)) - { - tmp = gen_rtx_MULT (DImode, copy_rtx (subtarget), - GEN_INT (diff)); - tmp = gen_rtx_PLUS (DImode, tmp, add_op); - emit_insn (gen_rtx_SET (VOIDmode, target, tmp)); - } - else - return 0; - } - } - else - return 0; - - return 1; -} - -/* Look up the function X_floating library function name for the - given operation. */ - -static const char * -alpha_lookup_xfloating_lib_func (enum rtx_code code) -{ - struct xfloating_op - { - const enum rtx_code code; - const char *const func; - }; - - static const struct xfloating_op vms_xfloating_ops[] = - { - { PLUS, "OTS$ADD_X" }, - { MINUS, "OTS$SUB_X" }, - { MULT, "OTS$MUL_X" }, - { DIV, "OTS$DIV_X" }, - { EQ, "OTS$EQL_X" }, - { NE, "OTS$NEQ_X" }, - { LT, "OTS$LSS_X" }, - { LE, "OTS$LEQ_X" }, - { GT, "OTS$GTR_X" }, - { GE, "OTS$GEQ_X" }, - { FIX, "OTS$CVTXQ" }, - { FLOAT, "OTS$CVTQX" }, - { UNSIGNED_FLOAT, "OTS$CVTQUX" }, - { FLOAT_EXTEND, "OTS$CVT_FLOAT_T_X" }, - { FLOAT_TRUNCATE, "OTS$CVT_FLOAT_X_T" }, - }; - - static const struct xfloating_op osf_xfloating_ops[] = - { - { PLUS, "_OtsAddX" }, - { MINUS, "_OtsSubX" }, - { MULT, "_OtsMulX" }, - { DIV, "_OtsDivX" }, - { EQ, "_OtsEqlX" }, - { NE, "_OtsNeqX" }, - { LT, "_OtsLssX" }, - { LE, "_OtsLeqX" }, - { GT, "_OtsGtrX" }, - { GE, "_OtsGeqX" }, - { FIX, "_OtsCvtXQ" }, - { FLOAT, "_OtsCvtQX" }, - { UNSIGNED_FLOAT, "_OtsCvtQUX" }, - { FLOAT_EXTEND, "_OtsConvertFloatTX" }, - { FLOAT_TRUNCATE, "_OtsConvertFloatXT" }, - }; - - const struct xfloating_op *ops; - const long n = ARRAY_SIZE (osf_xfloating_ops); - long i; - - /* How irritating. Nothing to key off for the table. Hardcode - knowledge of the G_floating routines. */ - if (TARGET_FLOAT_VAX) - { - if (TARGET_ABI_OPEN_VMS) - { - if (code == FLOAT_EXTEND) - return "OTS$CVT_FLOAT_G_X"; - if (code == FLOAT_TRUNCATE) - return "OTS$CVT_FLOAT_X_G"; - } - else - { - if (code == FLOAT_EXTEND) - return "_OtsConvertFloatGX"; - if (code == FLOAT_TRUNCATE) - return "_OtsConvertFloatXG"; - } - } - - if (TARGET_ABI_OPEN_VMS) - ops = vms_xfloating_ops; - else - ops = osf_xfloating_ops; - - for (i = 0; i < n; ++i) - if (ops[i].code == code) - return ops[i].func; - - abort(); -} - -/* Most X_floating operations take the rounding mode as an argument. - Compute that here. */ - -static int -alpha_compute_xfloating_mode_arg (enum rtx_code code, - enum alpha_fp_rounding_mode round) -{ - int mode; - - switch (round) - { - case ALPHA_FPRM_NORM: - mode = 2; - break; - case ALPHA_FPRM_MINF: - mode = 1; - break; - case ALPHA_FPRM_CHOP: - mode = 0; - break; - case ALPHA_FPRM_DYN: - mode = 4; - break; - default: - abort (); - - /* XXX For reference, round to +inf is mode = 3. */ - } - - if (code == FLOAT_TRUNCATE && alpha_fptm == ALPHA_FPTM_N) - mode |= 0x10000; - - return mode; -} - -/* Emit an X_floating library function call. - - Note that these functions do not follow normal calling conventions: - TFmode arguments are passed in two integer registers (as opposed to - indirect); TFmode return values appear in R16+R17. - - FUNC is the function name to call. - TARGET is where the output belongs. - OPERANDS are the inputs. - NOPERANDS is the count of inputs. - EQUIV is the expression equivalent for the function. -*/ - -static void -alpha_emit_xfloating_libcall (const char *func, rtx target, rtx operands[], - int noperands, rtx equiv) -{ - rtx usage = NULL_RTX, tmp, reg; - int regno = 16, i; - - start_sequence (); - - for (i = 0; i < noperands; ++i) - { - switch (GET_MODE (operands[i])) - { - case TFmode: - reg = gen_rtx_REG (TFmode, regno); - regno += 2; - break; - - case DFmode: - reg = gen_rtx_REG (DFmode, regno + 32); - regno += 1; - break; - - case VOIDmode: - if (GET_CODE (operands[i]) != CONST_INT) - abort (); - /* FALLTHRU */ - case DImode: - reg = gen_rtx_REG (DImode, regno); - regno += 1; - break; - - default: - abort (); - } - - emit_move_insn (reg, operands[i]); - usage = alloc_EXPR_LIST (0, gen_rtx_USE (VOIDmode, reg), usage); - } - - switch (GET_MODE (target)) - { - case TFmode: - reg = gen_rtx_REG (TFmode, 16); - break; - case DFmode: - reg = gen_rtx_REG (DFmode, 32); - break; - case DImode: - reg = gen_rtx_REG (DImode, 0); - break; - default: - abort (); - } - - tmp = gen_rtx_MEM (QImode, init_one_libfunc (func)); - tmp = emit_call_insn (GEN_CALL_VALUE (reg, tmp, const0_rtx, - const0_rtx, const0_rtx)); - CALL_INSN_FUNCTION_USAGE (tmp) = usage; - - tmp = get_insns (); - end_sequence (); - - emit_libcall_block (tmp, target, reg, equiv); -} - -/* Emit an X_floating library function call for arithmetic (+,-,*,/). */ - -void -alpha_emit_xfloating_arith (enum rtx_code code, rtx operands[]) -{ - const char *func; - int mode; - rtx out_operands[3]; - - func = alpha_lookup_xfloating_lib_func (code); - mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm); - - out_operands[0] = operands[1]; - out_operands[1] = operands[2]; - out_operands[2] = GEN_INT (mode); - alpha_emit_xfloating_libcall (func, operands[0], out_operands, 3, - gen_rtx_fmt_ee (code, TFmode, operands[1], - operands[2])); -} - -/* Emit an X_floating library function call for a comparison. */ - -static rtx -alpha_emit_xfloating_compare (enum rtx_code code, rtx op0, rtx op1) -{ - const char *func; - rtx out, operands[2]; - - func = alpha_lookup_xfloating_lib_func (code); - - operands[0] = op0; - operands[1] = op1; - out = gen_reg_rtx (DImode); - - /* ??? Strange mode for equiv because what's actually returned - is -1,0,1, not a proper boolean value. */ - alpha_emit_xfloating_libcall (func, out, operands, 2, - gen_rtx_fmt_ee (code, CCmode, op0, op1)); - - return out; -} - -/* Emit an X_floating library function call for a conversion. */ - -void -alpha_emit_xfloating_cvt (enum rtx_code orig_code, rtx operands[]) -{ - int noperands = 1, mode; - rtx out_operands[2]; - const char *func; - enum rtx_code code = orig_code; - - if (code == UNSIGNED_FIX) - code = FIX; - - func = alpha_lookup_xfloating_lib_func (code); - - out_operands[0] = operands[1]; - - switch (code) - { - case FIX: - mode = alpha_compute_xfloating_mode_arg (code, ALPHA_FPRM_CHOP); - out_operands[1] = GEN_INT (mode); - noperands = 2; - break; - case FLOAT_TRUNCATE: - mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm); - out_operands[1] = GEN_INT (mode); - noperands = 2; - break; - default: - break; - } - - alpha_emit_xfloating_libcall (func, operands[0], out_operands, noperands, - gen_rtx_fmt_e (orig_code, - GET_MODE (operands[0]), - operands[1])); -} - -/* Split a TFmode OP[1] into DImode OP[2,3] and likewise for - OP[0] into OP[0,1]. Naturally, output operand ordering is - little-endian. */ - -void -alpha_split_tfmode_pair (rtx operands[4]) -{ - if (GET_CODE (operands[1]) == REG) - { - operands[3] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1); - operands[2] = gen_rtx_REG (DImode, REGNO (operands[1])); - } - else if (GET_CODE (operands[1]) == MEM) - { - operands[3] = adjust_address (operands[1], DImode, 8); - operands[2] = adjust_address (operands[1], DImode, 0); - } - else if (operands[1] == CONST0_RTX (TFmode)) - operands[2] = operands[3] = const0_rtx; - else - abort (); - - if (GET_CODE (operands[0]) == REG) - { - operands[1] = gen_rtx_REG (DImode, REGNO (operands[0]) + 1); - operands[0] = gen_rtx_REG (DImode, REGNO (operands[0])); - } - else if (GET_CODE (operands[0]) == MEM) - { - operands[1] = adjust_address (operands[0], DImode, 8); - operands[0] = adjust_address (operands[0], DImode, 0); - } - else - abort (); -} - -/* Implement negtf2 or abstf2. Op0 is destination, op1 is source, - op2 is a register containing the sign bit, operation is the - logical operation to be performed. */ - -void -alpha_split_tfmode_frobsign (rtx operands[3], rtx (*operation) (rtx, rtx, rtx)) -{ - rtx high_bit = operands[2]; - rtx scratch; - int move; - - alpha_split_tfmode_pair (operands); - - /* Detect three flavors of operand overlap. */ - move = 1; - if (rtx_equal_p (operands[0], operands[2])) - move = 0; - else if (rtx_equal_p (operands[1], operands[2])) - { - if (rtx_equal_p (operands[0], high_bit)) - move = 2; - else - move = -1; - } - - if (move < 0) - emit_move_insn (operands[0], operands[2]); - - /* ??? If the destination overlaps both source tf and high_bit, then - assume source tf is dead in its entirety and use the other half - for a scratch register. Otherwise "scratch" is just the proper - destination register. */ - scratch = operands[move < 2 ? 1 : 3]; - - emit_insn ((*operation) (scratch, high_bit, operands[3])); - - if (move > 0) - { - emit_move_insn (operands[0], operands[2]); - if (move > 1) - emit_move_insn (operands[1], scratch); - } -} - -/* Use ext[wlq][lh] as the Architecture Handbook describes for extracting - unaligned data: - - unsigned: signed: - word: ldq_u r1,X(r11) ldq_u r1,X(r11) - ldq_u r2,X+1(r11) ldq_u r2,X+1(r11) - lda r3,X(r11) lda r3,X+2(r11) - extwl r1,r3,r1 extql r1,r3,r1 - extwh r2,r3,r2 extqh r2,r3,r2 - or r1.r2.r1 or r1,r2,r1 - sra r1,48,r1 - - long: ldq_u r1,X(r11) ldq_u r1,X(r11) - ldq_u r2,X+3(r11) ldq_u r2,X+3(r11) - lda r3,X(r11) lda r3,X(r11) - extll r1,r3,r1 extll r1,r3,r1 - extlh r2,r3,r2 extlh r2,r3,r2 - or r1.r2.r1 addl r1,r2,r1 - - quad: ldq_u r1,X(r11) - ldq_u r2,X+7(r11) - lda r3,X(r11) - extql r1,r3,r1 - extqh r2,r3,r2 - or r1.r2.r1 -*/ - -void -alpha_expand_unaligned_load (rtx tgt, rtx mem, HOST_WIDE_INT size, - HOST_WIDE_INT ofs, int sign) -{ - rtx meml, memh, addr, extl, exth, tmp, mema; - enum machine_mode mode; - - meml = gen_reg_rtx (DImode); - memh = gen_reg_rtx (DImode); - addr = gen_reg_rtx (DImode); - extl = gen_reg_rtx (DImode); - exth = gen_reg_rtx (DImode); - - mema = XEXP (mem, 0); - if (GET_CODE (mema) == LO_SUM) - mema = force_reg (Pmode, mema); - - /* AND addresses cannot be in any alias set, since they may implicitly - alias surrounding code. Ideally we'd have some alias set that - covered all types except those with alignment 8 or higher. */ - - tmp = change_address (mem, DImode, - gen_rtx_AND (DImode, - plus_constant (mema, ofs), - GEN_INT (-8))); - set_mem_alias_set (tmp, 0); - emit_move_insn (meml, tmp); - - tmp = change_address (mem, DImode, - gen_rtx_AND (DImode, - plus_constant (mema, ofs + size - 1), - GEN_INT (-8))); - set_mem_alias_set (tmp, 0); - emit_move_insn (memh, tmp); - - if (WORDS_BIG_ENDIAN && sign && (size == 2 || size == 4)) - { - emit_move_insn (addr, plus_constant (mema, -1)); - - emit_insn (gen_extqh_be (extl, meml, addr)); - emit_insn (gen_extxl_be (exth, memh, GEN_INT (64), addr)); - - addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN); - addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (64 - size*8), - addr, 1, OPTAB_WIDEN); - } - else if (sign && size == 2) - { - emit_move_insn (addr, plus_constant (mema, ofs+2)); - - emit_insn (gen_extxl_le (extl, meml, GEN_INT (64), addr)); - emit_insn (gen_extqh_le (exth, memh, addr)); - - /* We must use tgt here for the target. Alpha-vms port fails if we use - addr for the target, because addr is marked as a pointer and combine - knows that pointers are always sign-extended 32 bit values. */ - addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN); - addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (48), - addr, 1, OPTAB_WIDEN); - } - else - { - if (WORDS_BIG_ENDIAN) - { - emit_move_insn (addr, plus_constant (mema, ofs+size-1)); - switch ((int) size) - { - case 2: - emit_insn (gen_extwh_be (extl, meml, addr)); - mode = HImode; - break; - - case 4: - emit_insn (gen_extlh_be (extl, meml, addr)); - mode = SImode; - break; - - case 8: - emit_insn (gen_extqh_be (extl, meml, addr)); - mode = DImode; - break; - - default: - abort (); - } - emit_insn (gen_extxl_be (exth, memh, GEN_INT (size*8), addr)); - } - else - { - emit_move_insn (addr, plus_constant (mema, ofs)); - emit_insn (gen_extxl_le (extl, meml, GEN_INT (size*8), addr)); - switch ((int) size) - { - case 2: - emit_insn (gen_extwh_le (exth, memh, addr)); - mode = HImode; - break; - - case 4: - emit_insn (gen_extlh_le (exth, memh, addr)); - mode = SImode; - break; - - case 8: - emit_insn (gen_extqh_le (exth, memh, addr)); - mode = DImode; - break; - - default: - abort(); - } - } - - addr = expand_binop (mode, ior_optab, gen_lowpart (mode, extl), - gen_lowpart (mode, exth), gen_lowpart (mode, tgt), - sign, OPTAB_WIDEN); - } - - if (addr != tgt) - emit_move_insn (tgt, gen_lowpart(GET_MODE (tgt), addr)); -} - -/* Similarly, use ins and msk instructions to perform unaligned stores. */ - -void -alpha_expand_unaligned_store (rtx dst, rtx src, - HOST_WIDE_INT size, HOST_WIDE_INT ofs) -{ - rtx dstl, dsth, addr, insl, insh, meml, memh, dsta; - - dstl = gen_reg_rtx (DImode); - dsth = gen_reg_rtx (DImode); - insl = gen_reg_rtx (DImode); - insh = gen_reg_rtx (DImode); - - dsta = XEXP (dst, 0); - if (GET_CODE (dsta) == LO_SUM) - dsta = force_reg (Pmode, dsta); - - /* AND addresses cannot be in any alias set, since they may implicitly - alias surrounding code. Ideally we'd have some alias set that - covered all types except those with alignment 8 or higher. */ - - meml = change_address (dst, DImode, - gen_rtx_AND (DImode, - plus_constant (dsta, ofs), - GEN_INT (-8))); - set_mem_alias_set (meml, 0); - - memh = change_address (dst, DImode, - gen_rtx_AND (DImode, - plus_constant (dsta, ofs + size - 1), - GEN_INT (-8))); - set_mem_alias_set (memh, 0); - - emit_move_insn (dsth, memh); - emit_move_insn (dstl, meml); - if (WORDS_BIG_ENDIAN) - { - addr = copy_addr_to_reg (plus_constant (dsta, ofs+size-1)); - - if (src != const0_rtx) - { - switch ((int) size) - { - case 2: - emit_insn (gen_inswl_be (insh, gen_lowpart (HImode,src), addr)); - break; - case 4: - emit_insn (gen_insll_be (insh, gen_lowpart (SImode,src), addr)); - break; - case 8: - emit_insn (gen_insql_be (insh, gen_lowpart (DImode,src), addr)); - break; - } - emit_insn (gen_insxh (insl, gen_lowpart (DImode, src), - GEN_INT (size*8), addr)); - } - - switch ((int) size) - { - case 2: - emit_insn (gen_mskxl_be (dsth, dsth, GEN_INT (0xffff), addr)); - break; - case 4: - { - rtx msk = immed_double_const (0xffffffff, 0, DImode); - emit_insn (gen_mskxl_be (dsth, dsth, msk, addr)); - break; - } - case 8: - emit_insn (gen_mskxl_be (dsth, dsth, constm1_rtx, addr)); - break; - } - - emit_insn (gen_mskxh (dstl, dstl, GEN_INT (size*8), addr)); - } - else - { - addr = copy_addr_to_reg (plus_constant (dsta, ofs)); - - if (src != const0_rtx) - { - emit_insn (gen_insxh (insh, gen_lowpart (DImode, src), - GEN_INT (size*8), addr)); - - switch ((int) size) - { - case 2: - emit_insn (gen_inswl_le (insl, gen_lowpart (HImode, src), addr)); - break; - case 4: - emit_insn (gen_insll_le (insl, gen_lowpart (SImode, src), addr)); - break; - case 8: - emit_insn (gen_insql_le (insl, src, addr)); - break; - } - } - - emit_insn (gen_mskxh (dsth, dsth, GEN_INT (size*8), addr)); - - switch ((int) size) - { - case 2: - emit_insn (gen_mskxl_le (dstl, dstl, GEN_INT (0xffff), addr)); - break; - case 4: - { - rtx msk = immed_double_const (0xffffffff, 0, DImode); - emit_insn (gen_mskxl_le (dstl, dstl, msk, addr)); - break; - } - case 8: - emit_insn (gen_mskxl_le (dstl, dstl, constm1_rtx, addr)); - break; - } - } - - if (src != const0_rtx) - { - dsth = expand_binop (DImode, ior_optab, insh, dsth, dsth, 0, OPTAB_WIDEN); - dstl = expand_binop (DImode, ior_optab, insl, dstl, dstl, 0, OPTAB_WIDEN); - } - - if (WORDS_BIG_ENDIAN) - { - emit_move_insn (meml, dstl); - emit_move_insn (memh, dsth); - } - else - { - /* Must store high before low for degenerate case of aligned. */ - emit_move_insn (memh, dsth); - emit_move_insn (meml, dstl); - } -} - -/* The block move code tries to maximize speed by separating loads and - stores at the expense of register pressure: we load all of the data - before we store it back out. There are two secondary effects worth - mentioning, that this speeds copying to/from aligned and unaligned - buffers, and that it makes the code significantly easier to write. */ - -#define MAX_MOVE_WORDS 8 - -/* Load an integral number of consecutive unaligned quadwords. */ - -static void -alpha_expand_unaligned_load_words (rtx *out_regs, rtx smem, - HOST_WIDE_INT words, HOST_WIDE_INT ofs) -{ - rtx const im8 = GEN_INT (-8); - rtx const i64 = GEN_INT (64); - rtx ext_tmps[MAX_MOVE_WORDS], data_regs[MAX_MOVE_WORDS+1]; - rtx sreg, areg, tmp, smema; - HOST_WIDE_INT i; - - smema = XEXP (smem, 0); - if (GET_CODE (smema) == LO_SUM) - smema = force_reg (Pmode, smema); - - /* Generate all the tmp registers we need. */ - for (i = 0; i < words; ++i) - { - data_regs[i] = out_regs[i]; - ext_tmps[i] = gen_reg_rtx (DImode); - } - data_regs[words] = gen_reg_rtx (DImode); - - if (ofs != 0) - smem = adjust_address (smem, GET_MODE (smem), ofs); - - /* Load up all of the source data. */ - for (i = 0; i < words; ++i) - { - tmp = change_address (smem, DImode, - gen_rtx_AND (DImode, - plus_constant (smema, 8*i), - im8)); - set_mem_alias_set (tmp, 0); - emit_move_insn (data_regs[i], tmp); - } - - tmp = change_address (smem, DImode, - gen_rtx_AND (DImode, - plus_constant (smema, 8*words - 1), - im8)); - set_mem_alias_set (tmp, 0); - emit_move_insn (data_regs[words], tmp); - - /* Extract the half-word fragments. Unfortunately DEC decided to make - extxh with offset zero a noop instead of zeroing the register, so - we must take care of that edge condition ourselves with cmov. */ - - sreg = copy_addr_to_reg (smema); - areg = expand_binop (DImode, and_optab, sreg, GEN_INT (7), NULL, - 1, OPTAB_WIDEN); - if (WORDS_BIG_ENDIAN) - emit_move_insn (sreg, plus_constant (sreg, 7)); - for (i = 0; i < words; ++i) - { - if (WORDS_BIG_ENDIAN) - { - emit_insn (gen_extqh_be (data_regs[i], data_regs[i], sreg)); - emit_insn (gen_extxl_be (ext_tmps[i], data_regs[i+1], i64, sreg)); - } - else - { - emit_insn (gen_extxl_le (data_regs[i], data_regs[i], i64, sreg)); - emit_insn (gen_extqh_le (ext_tmps[i], data_regs[i+1], sreg)); - } - emit_insn (gen_rtx_SET (VOIDmode, ext_tmps[i], - gen_rtx_IF_THEN_ELSE (DImode, - gen_rtx_EQ (DImode, areg, - const0_rtx), - const0_rtx, ext_tmps[i]))); - } - - /* Merge the half-words into whole words. */ - for (i = 0; i < words; ++i) - { - out_regs[i] = expand_binop (DImode, ior_optab, data_regs[i], - ext_tmps[i], data_regs[i], 1, OPTAB_WIDEN); - } -} - -/* Store an integral number of consecutive unaligned quadwords. DATA_REGS - may be NULL to store zeros. */ - -static void -alpha_expand_unaligned_store_words (rtx *data_regs, rtx dmem, - HOST_WIDE_INT words, HOST_WIDE_INT ofs) -{ - rtx const im8 = GEN_INT (-8); - rtx const i64 = GEN_INT (64); - rtx ins_tmps[MAX_MOVE_WORDS]; - rtx st_tmp_1, st_tmp_2, dreg; - rtx st_addr_1, st_addr_2, dmema; - HOST_WIDE_INT i; - - dmema = XEXP (dmem, 0); - if (GET_CODE (dmema) == LO_SUM) - dmema = force_reg (Pmode, dmema); - - /* Generate all the tmp registers we need. */ - if (data_regs != NULL) - for (i = 0; i < words; ++i) - ins_tmps[i] = gen_reg_rtx(DImode); - st_tmp_1 = gen_reg_rtx(DImode); - st_tmp_2 = gen_reg_rtx(DImode); - - if (ofs != 0) - dmem = adjust_address (dmem, GET_MODE (dmem), ofs); - - st_addr_2 = change_address (dmem, DImode, - gen_rtx_AND (DImode, - plus_constant (dmema, words*8 - 1), - im8)); - set_mem_alias_set (st_addr_2, 0); - - st_addr_1 = change_address (dmem, DImode, - gen_rtx_AND (DImode, dmema, im8)); - set_mem_alias_set (st_addr_1, 0); - - /* Load up the destination end bits. */ - emit_move_insn (st_tmp_2, st_addr_2); - emit_move_insn (st_tmp_1, st_addr_1); - - /* Shift the input data into place. */ - dreg = copy_addr_to_reg (dmema); - if (WORDS_BIG_ENDIAN) - emit_move_insn (dreg, plus_constant (dreg, 7)); - if (data_regs != NULL) - { - for (i = words-1; i >= 0; --i) - { - if (WORDS_BIG_ENDIAN) - { - emit_insn (gen_insql_be (ins_tmps[i], data_regs[i], dreg)); - emit_insn (gen_insxh (data_regs[i], data_regs[i], i64, dreg)); - } - else - { - emit_insn (gen_insxh (ins_tmps[i], data_regs[i], i64, dreg)); - emit_insn (gen_insql_le (data_regs[i], data_regs[i], dreg)); - } - } - for (i = words-1; i > 0; --i) - { - ins_tmps[i-1] = expand_binop (DImode, ior_optab, data_regs[i], - ins_tmps[i-1], ins_tmps[i-1], 1, - OPTAB_WIDEN); - } - } - - /* Split and merge the ends with the destination data. */ - if (WORDS_BIG_ENDIAN) - { - emit_insn (gen_mskxl_be (st_tmp_2, st_tmp_2, constm1_rtx, dreg)); - emit_insn (gen_mskxh (st_tmp_1, st_tmp_1, i64, dreg)); - } - else - { - emit_insn (gen_mskxh (st_tmp_2, st_tmp_2, i64, dreg)); - emit_insn (gen_mskxl_le (st_tmp_1, st_tmp_1, constm1_rtx, dreg)); - } - - if (data_regs != NULL) - { - st_tmp_2 = expand_binop (DImode, ior_optab, st_tmp_2, ins_tmps[words-1], - st_tmp_2, 1, OPTAB_WIDEN); - st_tmp_1 = expand_binop (DImode, ior_optab, st_tmp_1, data_regs[0], - st_tmp_1, 1, OPTAB_WIDEN); - } - - /* Store it all. */ - if (WORDS_BIG_ENDIAN) - emit_move_insn (st_addr_1, st_tmp_1); - else - emit_move_insn (st_addr_2, st_tmp_2); - for (i = words-1; i > 0; --i) - { - rtx tmp = change_address (dmem, DImode, - gen_rtx_AND (DImode, - plus_constant(dmema, - WORDS_BIG_ENDIAN ? i*8-1 : i*8), - im8)); - set_mem_alias_set (tmp, 0); - emit_move_insn (tmp, data_regs ? ins_tmps[i-1] : const0_rtx); - } - if (WORDS_BIG_ENDIAN) - emit_move_insn (st_addr_2, st_tmp_2); - else - emit_move_insn (st_addr_1, st_tmp_1); -} - - -/* Expand string/block move operations. - - operands[0] is the pointer to the destination. - operands[1] is the pointer to the source. - operands[2] is the number of bytes to move. - operands[3] is the alignment. */ - -int -alpha_expand_block_move (rtx operands[]) -{ - rtx bytes_rtx = operands[2]; - rtx align_rtx = operands[3]; - HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx); - HOST_WIDE_INT bytes = orig_bytes; - HOST_WIDE_INT src_align = INTVAL (align_rtx) * BITS_PER_UNIT; - HOST_WIDE_INT dst_align = src_align; - rtx orig_src = operands[1]; - rtx orig_dst = operands[0]; - rtx data_regs[2 * MAX_MOVE_WORDS + 16]; - rtx tmp; - unsigned int i, words, ofs, nregs = 0; - - if (orig_bytes <= 0) - return 1; - else if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD) - return 0; - - /* Look for additional alignment information from recorded register info. */ - - tmp = XEXP (orig_src, 0); - if (GET_CODE (tmp) == REG) - src_align = MAX (src_align, REGNO_POINTER_ALIGN (REGNO (tmp))); - else if (GET_CODE (tmp) == PLUS - && GET_CODE (XEXP (tmp, 0)) == REG - && GET_CODE (XEXP (tmp, 1)) == CONST_INT) - { - unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1)); - unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0))); - - if (a > src_align) - { - if (a >= 64 && c % 8 == 0) - src_align = 64; - else if (a >= 32 && c % 4 == 0) - src_align = 32; - else if (a >= 16 && c % 2 == 0) - src_align = 16; - } - } - - tmp = XEXP (orig_dst, 0); - if (GET_CODE (tmp) == REG) - dst_align = MAX (dst_align, REGNO_POINTER_ALIGN (REGNO (tmp))); - else if (GET_CODE (tmp) == PLUS - && GET_CODE (XEXP (tmp, 0)) == REG - && GET_CODE (XEXP (tmp, 1)) == CONST_INT) - { - unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1)); - unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0))); - - if (a > dst_align) - { - if (a >= 64 && c % 8 == 0) - dst_align = 64; - else if (a >= 32 && c % 4 == 0) - dst_align = 32; - else if (a >= 16 && c % 2 == 0) - dst_align = 16; - } - } - - /* Load the entire block into registers. */ - if (GET_CODE (XEXP (orig_src, 0)) == ADDRESSOF) - { - enum machine_mode mode; - - tmp = XEXP (XEXP (orig_src, 0), 0); - - /* Don't use the existing register if we're reading more than - is held in the register. Nor if there is not a mode that - handles the exact size. */ - mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1); - if (GET_CODE (tmp) == REG - && mode != BLKmode - && GET_MODE_SIZE (GET_MODE (tmp)) >= bytes) - { - if (mode == TImode) - { - data_regs[nregs] = gen_lowpart (DImode, tmp); - data_regs[nregs + 1] = gen_highpart (DImode, tmp); - nregs += 2; - } - else - data_regs[nregs++] = gen_lowpart (mode, tmp); - - goto src_done; - } - - /* No appropriate mode; fall back on memory. */ - orig_src = replace_equiv_address (orig_src, - copy_addr_to_reg (XEXP (orig_src, 0))); - src_align = GET_MODE_BITSIZE (GET_MODE (tmp)); - } - - ofs = 0; - if (src_align >= 64 && bytes >= 8) - { - words = bytes / 8; - - for (i = 0; i < words; ++i) - data_regs[nregs + i] = gen_reg_rtx (DImode); - - for (i = 0; i < words; ++i) - emit_move_insn (data_regs[nregs + i], - adjust_address (orig_src, DImode, ofs + i * 8)); - - nregs += words; - bytes -= words * 8; - ofs += words * 8; - } - - if (src_align >= 32 && bytes >= 4) - { - words = bytes / 4; - - for (i = 0; i < words; ++i) - data_regs[nregs + i] = gen_reg_rtx (SImode); - - for (i = 0; i < words; ++i) - emit_move_insn (data_regs[nregs + i], - adjust_address (orig_src, SImode, ofs + i * 4)); - - nregs += words; - bytes -= words * 4; - ofs += words * 4; - } - - if (bytes >= 8) - { - words = bytes / 8; - - for (i = 0; i < words+1; ++i) - data_regs[nregs + i] = gen_reg_rtx (DImode); - - alpha_expand_unaligned_load_words (data_regs + nregs, orig_src, - words, ofs); - - nregs += words; - bytes -= words * 8; - ofs += words * 8; - } - - if (! TARGET_BWX && bytes >= 4) - { - data_regs[nregs++] = tmp = gen_reg_rtx (SImode); - alpha_expand_unaligned_load (tmp, orig_src, 4, ofs, 0); - bytes -= 4; - ofs += 4; - } - - if (bytes >= 2) - { - if (src_align >= 16) - { - do { - data_regs[nregs++] = tmp = gen_reg_rtx (HImode); - emit_move_insn (tmp, adjust_address (orig_src, HImode, ofs)); - bytes -= 2; - ofs += 2; - } while (bytes >= 2); - } - else if (! TARGET_BWX) - { - data_regs[nregs++] = tmp = gen_reg_rtx (HImode); - alpha_expand_unaligned_load (tmp, orig_src, 2, ofs, 0); - bytes -= 2; - ofs += 2; - } - } - - while (bytes > 0) - { - data_regs[nregs++] = tmp = gen_reg_rtx (QImode); - emit_move_insn (tmp, adjust_address (orig_src, QImode, ofs)); - bytes -= 1; - ofs += 1; - } - - src_done: - - if (nregs > ARRAY_SIZE (data_regs)) - abort (); - - /* Now save it back out again. */ - - i = 0, ofs = 0; - - if (GET_CODE (XEXP (orig_dst, 0)) == ADDRESSOF) - { - enum machine_mode mode; - tmp = XEXP (XEXP (orig_dst, 0), 0); - - mode = mode_for_size (orig_bytes * BITS_PER_UNIT, MODE_INT, 1); - if (GET_CODE (tmp) == REG && GET_MODE (tmp) == mode) - { - if (nregs == 1) - { - emit_move_insn (tmp, data_regs[0]); - i = 1; - goto dst_done; - } - - else if (nregs == 2 && mode == TImode) - { - /* Undo the subregging done above when copying between - two TImode registers. */ - if (GET_CODE (data_regs[0]) == SUBREG - && GET_MODE (SUBREG_REG (data_regs[0])) == TImode) - emit_move_insn (tmp, SUBREG_REG (data_regs[0])); - else - { - rtx seq; - - start_sequence (); - emit_move_insn (gen_lowpart (DImode, tmp), data_regs[0]); - emit_move_insn (gen_highpart (DImode, tmp), data_regs[1]); - seq = get_insns (); - end_sequence (); - - emit_no_conflict_block (seq, tmp, data_regs[0], - data_regs[1], NULL_RTX); - } - - i = 2; - goto dst_done; - } - } - - /* ??? If nregs > 1, consider reconstructing the word in regs. */ - /* ??? Optimize mode < dst_mode with strict_low_part. */ - - /* No appropriate mode; fall back on memory. We can speed things - up by recognizing extra alignment information. */ - orig_dst = replace_equiv_address (orig_dst, - copy_addr_to_reg (XEXP (orig_dst, 0))); - dst_align = GET_MODE_BITSIZE (GET_MODE (tmp)); - } - - /* Write out the data in whatever chunks reading the source allowed. */ - if (dst_align >= 64) - { - while (i < nregs && GET_MODE (data_regs[i]) == DImode) - { - emit_move_insn (adjust_address (orig_dst, DImode, ofs), - data_regs[i]); - ofs += 8; - i++; - } - } - - if (dst_align >= 32) - { - /* If the source has remaining DImode regs, write them out in - two pieces. */ - while (i < nregs && GET_MODE (data_regs[i]) == DImode) - { - tmp = expand_binop (DImode, lshr_optab, data_regs[i], GEN_INT (32), - NULL_RTX, 1, OPTAB_WIDEN); - - emit_move_insn (adjust_address (orig_dst, SImode, ofs), - gen_lowpart (SImode, data_regs[i])); - emit_move_insn (adjust_address (orig_dst, SImode, ofs + 4), - gen_lowpart (SImode, tmp)); - ofs += 8; - i++; - } - - while (i < nregs && GET_MODE (data_regs[i]) == SImode) - { - emit_move_insn (adjust_address (orig_dst, SImode, ofs), - data_regs[i]); - ofs += 4; - i++; - } - } - - if (i < nregs && GET_MODE (data_regs[i]) == DImode) - { - /* Write out a remaining block of words using unaligned methods. */ - - for (words = 1; i + words < nregs; words++) - if (GET_MODE (data_regs[i + words]) != DImode) - break; - - if (words == 1) - alpha_expand_unaligned_store (orig_dst, data_regs[i], 8, ofs); - else - alpha_expand_unaligned_store_words (data_regs + i, orig_dst, - words, ofs); - - i += words; - ofs += words * 8; - } - - /* Due to the above, this won't be aligned. */ - /* ??? If we have more than one of these, consider constructing full - words in registers and using alpha_expand_unaligned_store_words. */ - while (i < nregs && GET_MODE (data_regs[i]) == SImode) - { - alpha_expand_unaligned_store (orig_dst, data_regs[i], 4, ofs); - ofs += 4; - i++; - } - - if (dst_align >= 16) - while (i < nregs && GET_MODE (data_regs[i]) == HImode) - { - emit_move_insn (adjust_address (orig_dst, HImode, ofs), data_regs[i]); - i++; - ofs += 2; - } - else - while (i < nregs && GET_MODE (data_regs[i]) == HImode) - { - alpha_expand_unaligned_store (orig_dst, data_regs[i], 2, ofs); - i++; - ofs += 2; - } - - while (i < nregs && GET_MODE (data_regs[i]) == QImode) - { - emit_move_insn (adjust_address (orig_dst, QImode, ofs), data_regs[i]); - i++; - ofs += 1; - } - - dst_done: - - if (i != nregs) - abort (); - - return 1; -} - -int -alpha_expand_block_clear (rtx operands[]) -{ - rtx bytes_rtx = operands[1]; - rtx align_rtx = operands[2]; - HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx); - HOST_WIDE_INT bytes = orig_bytes; - HOST_WIDE_INT align = INTVAL (align_rtx) * BITS_PER_UNIT; - HOST_WIDE_INT alignofs = 0; - rtx orig_dst = operands[0]; - rtx tmp; - int i, words, ofs = 0; - - if (orig_bytes <= 0) - return 1; - if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD) - return 0; - - /* Look for stricter alignment. */ - tmp = XEXP (orig_dst, 0); - if (GET_CODE (tmp) == REG) - align = MAX (align, REGNO_POINTER_ALIGN (REGNO (tmp))); - else if (GET_CODE (tmp) == PLUS - && GET_CODE (XEXP (tmp, 0)) == REG - && GET_CODE (XEXP (tmp, 1)) == CONST_INT) - { - HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1)); - int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0))); - - if (a > align) - { - if (a >= 64) - align = a, alignofs = 8 - c % 8; - else if (a >= 32) - align = a, alignofs = 4 - c % 4; - else if (a >= 16) - align = a, alignofs = 2 - c % 2; - } - } - else if (GET_CODE (tmp) == ADDRESSOF) - { - enum machine_mode mode; - - mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1); - if (GET_MODE (XEXP (tmp, 0)) == mode) - { - emit_move_insn (XEXP (tmp, 0), const0_rtx); - return 1; - } - - /* No appropriate mode; fall back on memory. */ - orig_dst = replace_equiv_address (orig_dst, copy_addr_to_reg (tmp)); - align = GET_MODE_BITSIZE (GET_MODE (XEXP (tmp, 0))); - } - - /* Handle an unaligned prefix first. */ - - if (alignofs > 0) - { -#if HOST_BITS_PER_WIDE_INT >= 64 - /* Given that alignofs is bounded by align, the only time BWX could - generate three stores is for a 7 byte fill. Prefer two individual - stores over a load/mask/store sequence. */ - if ((!TARGET_BWX || alignofs == 7) - && align >= 32 - && !(alignofs == 4 && bytes >= 4)) - { - enum machine_mode mode = (align >= 64 ? DImode : SImode); - int inv_alignofs = (align >= 64 ? 8 : 4) - alignofs; - rtx mem, tmp; - HOST_WIDE_INT mask; - - mem = adjust_address (orig_dst, mode, ofs - inv_alignofs); - set_mem_alias_set (mem, 0); - - mask = ~(~(HOST_WIDE_INT)0 << (inv_alignofs * 8)); - if (bytes < alignofs) - { - mask |= ~(HOST_WIDE_INT)0 << ((inv_alignofs + bytes) * 8); - ofs += bytes; - bytes = 0; - } - else - { - bytes -= alignofs; - ofs += alignofs; - } - alignofs = 0; - - tmp = expand_binop (mode, and_optab, mem, GEN_INT (mask), - NULL_RTX, 1, OPTAB_WIDEN); - - emit_move_insn (mem, tmp); - } -#endif - - if (TARGET_BWX && (alignofs & 1) && bytes >= 1) - { - emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx); - bytes -= 1; - ofs += 1; - alignofs -= 1; - } - if (TARGET_BWX && align >= 16 && (alignofs & 3) == 2 && bytes >= 2) - { - emit_move_insn (adjust_address (orig_dst, HImode, ofs), const0_rtx); - bytes -= 2; - ofs += 2; - alignofs -= 2; - } - if (alignofs == 4 && bytes >= 4) - { - emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx); - bytes -= 4; - ofs += 4; - alignofs = 0; - } - - /* If we've not used the extra lead alignment information by now, - we won't be able to. Downgrade align to match what's left over. */ - if (alignofs > 0) - { - alignofs = alignofs & -alignofs; - align = MIN (align, alignofs * BITS_PER_UNIT); - } - } - - /* Handle a block of contiguous long-words. */ - - if (align >= 64 && bytes >= 8) - { - words = bytes / 8; - - for (i = 0; i < words; ++i) - emit_move_insn (adjust_address (orig_dst, DImode, ofs + i * 8), - const0_rtx); - - bytes -= words * 8; - ofs += words * 8; - } - - /* If the block is large and appropriately aligned, emit a single - store followed by a sequence of stq_u insns. */ - - if (align >= 32 && bytes > 16) - { - rtx orig_dsta; - - emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx); - bytes -= 4; - ofs += 4; - - orig_dsta = XEXP (orig_dst, 0); - if (GET_CODE (orig_dsta) == LO_SUM) - orig_dsta = force_reg (Pmode, orig_dsta); - - words = bytes / 8; - for (i = 0; i < words; ++i) - { - rtx mem - = change_address (orig_dst, DImode, - gen_rtx_AND (DImode, - plus_constant (orig_dsta, ofs + i*8), - GEN_INT (-8))); - set_mem_alias_set (mem, 0); - emit_move_insn (mem, const0_rtx); - } - - /* Depending on the alignment, the first stq_u may have overlapped - with the initial stl, which means that the last stq_u didn't - write as much as it would appear. Leave those questionable bytes - unaccounted for. */ - bytes -= words * 8 - 4; - ofs += words * 8 - 4; - } - - /* Handle a smaller block of aligned words. */ - - if ((align >= 64 && bytes == 4) - || (align == 32 && bytes >= 4)) - { - words = bytes / 4; - - for (i = 0; i < words; ++i) - emit_move_insn (adjust_address (orig_dst, SImode, ofs + i * 4), - const0_rtx); - - bytes -= words * 4; - ofs += words * 4; - } - - /* An unaligned block uses stq_u stores for as many as possible. */ - - if (bytes >= 8) - { - words = bytes / 8; - - alpha_expand_unaligned_store_words (NULL, orig_dst, words, ofs); - - bytes -= words * 8; - ofs += words * 8; - } - - /* Next clean up any trailing pieces. */ - -#if HOST_BITS_PER_WIDE_INT >= 64 - /* Count the number of bits in BYTES for which aligned stores could - be emitted. */ - words = 0; - for (i = (TARGET_BWX ? 1 : 4); i * BITS_PER_UNIT <= align ; i <<= 1) - if (bytes & i) - words += 1; - - /* If we have appropriate alignment (and it wouldn't take too many - instructions otherwise), mask out the bytes we need. */ - if (TARGET_BWX ? words > 2 : bytes > 0) - { - if (align >= 64) - { - rtx mem, tmp; - HOST_WIDE_INT mask; - - mem = adjust_address (orig_dst, DImode, ofs); - set_mem_alias_set (mem, 0); - - mask = ~(HOST_WIDE_INT)0 << (bytes * 8); - - tmp = expand_binop (DImode, and_optab, mem, GEN_INT (mask), - NULL_RTX, 1, OPTAB_WIDEN); - - emit_move_insn (mem, tmp); - return 1; - } - else if (align >= 32 && bytes < 4) - { - rtx mem, tmp; - HOST_WIDE_INT mask; - - mem = adjust_address (orig_dst, SImode, ofs); - set_mem_alias_set (mem, 0); - - mask = ~(HOST_WIDE_INT)0 << (bytes * 8); - - tmp = expand_binop (SImode, and_optab, mem, GEN_INT (mask), - NULL_RTX, 1, OPTAB_WIDEN); - - emit_move_insn (mem, tmp); - return 1; - } - } -#endif - - if (!TARGET_BWX && bytes >= 4) - { - alpha_expand_unaligned_store (orig_dst, const0_rtx, 4, ofs); - bytes -= 4; - ofs += 4; - } - - if (bytes >= 2) - { - if (align >= 16) - { - do { - emit_move_insn (adjust_address (orig_dst, HImode, ofs), - const0_rtx); - bytes -= 2; - ofs += 2; - } while (bytes >= 2); - } - else if (! TARGET_BWX) - { - alpha_expand_unaligned_store (orig_dst, const0_rtx, 2, ofs); - bytes -= 2; - ofs += 2; - } - } - - while (bytes > 0) - { - emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx); - bytes -= 1; - ofs += 1; - } - - return 1; -} - -/* Returns a mask so that zap(x, value) == x & mask. */ - -rtx -alpha_expand_zap_mask (HOST_WIDE_INT value) -{ - rtx result; - int i; - - if (HOST_BITS_PER_WIDE_INT >= 64) - { - HOST_WIDE_INT mask = 0; - - for (i = 7; i >= 0; --i) - { - mask <<= 8; - if (!((value >> i) & 1)) - mask |= 0xff; - } - - result = gen_int_mode (mask, DImode); - } - else if (HOST_BITS_PER_WIDE_INT == 32) - { - HOST_WIDE_INT mask_lo = 0, mask_hi = 0; - - for (i = 7; i >= 4; --i) - { - mask_hi <<= 8; - if (!((value >> i) & 1)) - mask_hi |= 0xff; - } - - for (i = 3; i >= 0; --i) - { - mask_lo <<= 8; - if (!((value >> i) & 1)) - mask_lo |= 0xff; - } - - result = immed_double_const (mask_lo, mask_hi, DImode); - } - else - abort (); - - return result; -} - -void -alpha_expand_builtin_vector_binop (rtx (*gen) (rtx, rtx, rtx), - enum machine_mode mode, - rtx op0, rtx op1, rtx op2) -{ - op0 = gen_lowpart (mode, op0); - - if (op1 == const0_rtx) - op1 = CONST0_RTX (mode); - else - op1 = gen_lowpart (mode, op1); - - if (op2 == const0_rtx) - op2 = CONST0_RTX (mode); - else - op2 = gen_lowpart (mode, op2); - - emit_insn ((*gen) (op0, op1, op2)); -} - -/* Adjust the cost of a scheduling dependency. Return the new cost of - a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ - -static int -alpha_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost) -{ - enum attr_type insn_type, dep_insn_type; - - /* If the dependence is an anti-dependence, there is no cost. For an - output dependence, there is sometimes a cost, but it doesn't seem - worth handling those few cases. */ - if (REG_NOTE_KIND (link) != 0) - return cost; - - /* If we can't recognize the insns, we can't really do anything. */ - if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0) - return cost; - - insn_type = get_attr_type (insn); - dep_insn_type = get_attr_type (dep_insn); - - /* Bring in the user-defined memory latency. */ - if (dep_insn_type == TYPE_ILD - || dep_insn_type == TYPE_FLD - || dep_insn_type == TYPE_LDSYM) - cost += alpha_memory_latency-1; - - /* Everything else handled in DFA bypasses now. */ - - return cost; -} - -/* The number of instructions that can be issued per cycle. */ - -static int -alpha_issue_rate (void) -{ - return (alpha_cpu == PROCESSOR_EV4 ? 2 : 4); -} - -static int -alpha_use_dfa_pipeline_interface (void) -{ - return true; -} - -/* How many alternative schedules to try. This should be as wide as the - scheduling freedom in the DFA, but no wider. Making this value too - large results extra work for the scheduler. - - For EV4, loads can be issued to either IB0 or IB1, thus we have 2 - alternative schedules. For EV5, we can choose between E0/E1 and - FA/FM. For EV6, an arithmetic insn can be issued to U0/U1/L0/L1. */ - -static int -alpha_multipass_dfa_lookahead (void) -{ - return (alpha_cpu == PROCESSOR_EV6 ? 4 : 2); -} - -/* Machine-specific function data. */ - -struct machine_function GTY(()) -{ - /* For unicosmk. */ - /* List of call information words for calls from this function. */ - struct rtx_def *first_ciw; - struct rtx_def *last_ciw; - int ciw_count; - - /* List of deferred case vectors. */ - struct rtx_def *addr_list; - - /* For OSF. */ - const char *some_ld_name; -}; - -/* How to allocate a 'struct machine_function'. */ - -static struct machine_function * -alpha_init_machine_status (void) -{ - return ((struct machine_function *) - ggc_alloc_cleared (sizeof (struct machine_function))); -} - -/* Functions to save and restore alpha_return_addr_rtx. */ - -/* Start the ball rolling with RETURN_ADDR_RTX. */ - -rtx -alpha_return_addr (int count, rtx frame ATTRIBUTE_UNUSED) -{ - if (count != 0) - return const0_rtx; - - return get_hard_reg_initial_val (Pmode, REG_RA); -} - -/* Return or create a pseudo containing the gp value for the current - function. Needed only if TARGET_LD_BUGGY_LDGP. */ - -rtx -alpha_gp_save_rtx (void) -{ - rtx r = get_hard_reg_initial_val (DImode, 29); - if (GET_CODE (r) != MEM) - r = gen_mem_addressof (r, NULL_TREE, /*rescan=*/true); - return r; -} - -static int -alpha_ra_ever_killed (void) -{ - rtx top; - - if (!has_hard_reg_initial_val (Pmode, REG_RA)) - return regs_ever_live[REG_RA]; - - push_topmost_sequence (); - top = get_insns (); - pop_topmost_sequence (); - - return reg_set_between_p (gen_rtx_REG (Pmode, REG_RA), top, NULL_RTX); -} - - -/* Return the trap mode suffix applicable to the current - instruction, or NULL. */ - -static const char * -get_trap_mode_suffix (void) -{ - enum attr_trap_suffix s = get_attr_trap_suffix (current_output_insn); - - switch (s) - { - case TRAP_SUFFIX_NONE: - return NULL; - - case TRAP_SUFFIX_SU: - if (alpha_fptm >= ALPHA_FPTM_SU) - return "su"; - return NULL; - - case TRAP_SUFFIX_SUI: - if (alpha_fptm >= ALPHA_FPTM_SUI) - return "sui"; - return NULL; - - case TRAP_SUFFIX_V_SV: - switch (alpha_fptm) - { - case ALPHA_FPTM_N: - return NULL; - case ALPHA_FPTM_U: - return "v"; - case ALPHA_FPTM_SU: - case ALPHA_FPTM_SUI: - return "sv"; - } - break; - - case TRAP_SUFFIX_V_SV_SVI: - switch (alpha_fptm) - { - case ALPHA_FPTM_N: - return NULL; - case ALPHA_FPTM_U: - return "v"; - case ALPHA_FPTM_SU: - return "sv"; - case ALPHA_FPTM_SUI: - return "svi"; - } - break; - - case TRAP_SUFFIX_U_SU_SUI: - switch (alpha_fptm) - { - case ALPHA_FPTM_N: - return NULL; - case ALPHA_FPTM_U: - return "u"; - case ALPHA_FPTM_SU: - return "su"; - case ALPHA_FPTM_SUI: - return "sui"; - } - break; - } - abort (); -} - -/* Return the rounding mode suffix applicable to the current - instruction, or NULL. */ - -static const char * -get_round_mode_suffix (void) -{ - enum attr_round_suffix s = get_attr_round_suffix (current_output_insn); - - switch (s) - { - case ROUND_SUFFIX_NONE: - return NULL; - case ROUND_SUFFIX_NORMAL: - switch (alpha_fprm) - { - case ALPHA_FPRM_NORM: - return NULL; - case ALPHA_FPRM_MINF: - return "m"; - case ALPHA_FPRM_CHOP: - return "c"; - case ALPHA_FPRM_DYN: - return "d"; - } - break; - - case ROUND_SUFFIX_C: - return "c"; - } - abort (); -} - -/* Locate some local-dynamic symbol still in use by this function - so that we can print its name in some movdi_er_tlsldm pattern. */ - -static int -get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED) -{ - rtx x = *px; - - if (GET_CODE (x) == SYMBOL_REF - && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC) - { - cfun->machine->some_ld_name = XSTR (x, 0); - return 1; - } - - return 0; -} - -static const char * -get_some_local_dynamic_name (void) -{ - rtx insn; - - if (cfun->machine->some_ld_name) - return cfun->machine->some_ld_name; - - for (insn = get_insns (); insn ; insn = NEXT_INSN (insn)) - if (INSN_P (insn) - && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0)) - return cfun->machine->some_ld_name; - - abort (); -} - -/* Print an operand. Recognize special options, documented below. */ - -void -print_operand (FILE *file, rtx x, int code) -{ - int i; - - switch (code) - { - case '~': - /* Print the assembler name of the current function. */ - assemble_name (file, alpha_fnname); - break; - - case '&': - assemble_name (file, get_some_local_dynamic_name ()); - break; - - case '/': - { - const char *trap = get_trap_mode_suffix (); - const char *round = get_round_mode_suffix (); - - if (trap || round) - fprintf (file, (TARGET_AS_SLASH_BEFORE_SUFFIX ? "/%s%s" : "%s%s"), - (trap ? trap : ""), (round ? round : "")); - break; - } - - case ',': - /* Generates single precision instruction suffix. */ - fputc ((TARGET_FLOAT_VAX ? 'f' : 's'), file); - break; - - case '-': - /* Generates double precision instruction suffix. */ - fputc ((TARGET_FLOAT_VAX ? 'g' : 't'), file); - break; - - case '+': - /* Generates a nop after a noreturn call at the very end of the - function. */ - if (next_real_insn (current_output_insn) == 0) - fprintf (file, "\n\tnop"); - break; - - case '#': - if (alpha_this_literal_sequence_number == 0) - alpha_this_literal_sequence_number = alpha_next_sequence_number++; - fprintf (file, "%d", alpha_this_literal_sequence_number); - break; - - case '*': - if (alpha_this_gpdisp_sequence_number == 0) - alpha_this_gpdisp_sequence_number = alpha_next_sequence_number++; - fprintf (file, "%d", alpha_this_gpdisp_sequence_number); - break; - - case 'H': - if (GET_CODE (x) == HIGH) - output_addr_const (file, XEXP (x, 0)); - else - output_operand_lossage ("invalid %%H value"); - break; - - case 'J': - { - const char *lituse; - - if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSGD_CALL) - { - x = XVECEXP (x, 0, 0); - lituse = "lituse_tlsgd"; - } - else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM_CALL) - { - x = XVECEXP (x, 0, 0); - lituse = "lituse_tlsldm"; - } - else if (GET_CODE (x) == CONST_INT) - lituse = "lituse_jsr"; - else - { - output_operand_lossage ("invalid %%J value"); - break; - } - - if (x != const0_rtx) - fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x)); - } - break; - - case 'j': - { - const char *lituse; - -#ifdef HAVE_AS_JSRDIRECT_RELOCS - lituse = "lituse_jsrdirect"; -#else - lituse = "lituse_jsr"; -#endif - - if (INTVAL (x) == 0) - abort (); - fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x)); - } - break; - case 'r': - /* If this operand is the constant zero, write it as "$31". */ - if (GET_CODE (x) == REG) - fprintf (file, "%s", reg_names[REGNO (x)]); - else if (x == CONST0_RTX (GET_MODE (x))) - fprintf (file, "$31"); - else - output_operand_lossage ("invalid %%r value"); - break; - - case 'R': - /* Similar, but for floating-point. */ - if (GET_CODE (x) == REG) - fprintf (file, "%s", reg_names[REGNO (x)]); - else if (x == CONST0_RTX (GET_MODE (x))) - fprintf (file, "$f31"); - else - output_operand_lossage ("invalid %%R value"); - break; - - case 'N': - /* Write the 1's complement of a constant. */ - if (GET_CODE (x) != CONST_INT) - output_operand_lossage ("invalid %%N value"); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x)); - break; - - case 'P': - /* Write 1 << C, for a constant C. */ - if (GET_CODE (x) != CONST_INT) - output_operand_lossage ("invalid %%P value"); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x)); - break; - - case 'h': - /* Write the high-order 16 bits of a constant, sign-extended. */ - if (GET_CODE (x) != CONST_INT) - output_operand_lossage ("invalid %%h value"); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16); - break; - - case 'L': - /* Write the low-order 16 bits of a constant, sign-extended. */ - if (GET_CODE (x) != CONST_INT) - output_operand_lossage ("invalid %%L value"); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, - (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000)); - break; - - case 'm': - /* Write mask for ZAP insn. */ - if (GET_CODE (x) == CONST_DOUBLE) - { - HOST_WIDE_INT mask = 0; - HOST_WIDE_INT value; - - value = CONST_DOUBLE_LOW (x); - for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; - i++, value >>= 8) - if (value & 0xff) - mask |= (1 << i); - - value = CONST_DOUBLE_HIGH (x); - for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; - i++, value >>= 8) - if (value & 0xff) - mask |= (1 << (i + sizeof (int))); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff); - } - - else if (GET_CODE (x) == CONST_INT) - { - HOST_WIDE_INT mask = 0, value = INTVAL (x); - - for (i = 0; i < 8; i++, value >>= 8) - if (value & 0xff) - mask |= (1 << i); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask); - } - else - output_operand_lossage ("invalid %%m value"); - break; - - case 'M': - /* 'b', 'w', 'l', or 'q' as the value of the constant. */ - if (GET_CODE (x) != CONST_INT - || (INTVAL (x) != 8 && INTVAL (x) != 16 - && INTVAL (x) != 32 && INTVAL (x) != 64)) - output_operand_lossage ("invalid %%M value"); - - fprintf (file, "%s", - (INTVAL (x) == 8 ? "b" - : INTVAL (x) == 16 ? "w" - : INTVAL (x) == 32 ? "l" - : "q")); - break; - - case 'U': - /* Similar, except do it from the mask. */ - if (GET_CODE (x) == CONST_INT) - { - HOST_WIDE_INT value = INTVAL (x); - - if (value == 0xff) - { - fputc ('b', file); - break; - } - if (value == 0xffff) - { - fputc ('w', file); - break; - } - if (value == 0xffffffff) - { - fputc ('l', file); - break; - } - if (value == -1) - { - fputc ('q', file); - break; - } - } - else if (HOST_BITS_PER_WIDE_INT == 32 - && GET_CODE (x) == CONST_DOUBLE - && CONST_DOUBLE_LOW (x) == 0xffffffff - && CONST_DOUBLE_HIGH (x) == 0) - { - fputc ('l', file); - break; - } - output_operand_lossage ("invalid %%U value"); - break; - - case 's': - /* Write the constant value divided by 8 for little-endian mode or - (56 - value) / 8 for big-endian mode. */ - - if (GET_CODE (x) != CONST_INT - || (unsigned HOST_WIDE_INT) INTVAL (x) >= (WORDS_BIG_ENDIAN - ? 56 - : 64) - || (INTVAL (x) & 7) != 0) - output_operand_lossage ("invalid %%s value"); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, - WORDS_BIG_ENDIAN - ? (56 - INTVAL (x)) / 8 - : INTVAL (x) / 8); - break; - - case 'S': - /* Same, except compute (64 - c) / 8 */ - - if (GET_CODE (x) != CONST_INT - && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64 - && (INTVAL (x) & 7) != 8) - output_operand_lossage ("invalid %%s value"); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8); - break; - - case 't': - { - /* On Unicos/Mk systems: use a DEX expression if the symbol - clashes with a register name. */ - int dex = unicosmk_need_dex (x); - if (dex) - fprintf (file, "DEX(%d)", dex); - else - output_addr_const (file, x); - } - break; - - case 'C': case 'D': case 'c': case 'd': - /* Write out comparison name. */ - { - enum rtx_code c = GET_CODE (x); - - if (GET_RTX_CLASS (c) != '<') - output_operand_lossage ("invalid %%C value"); - - else if (code == 'D') - c = reverse_condition (c); - else if (code == 'c') - c = swap_condition (c); - else if (code == 'd') - c = swap_condition (reverse_condition (c)); - - if (c == LEU) - fprintf (file, "ule"); - else if (c == LTU) - fprintf (file, "ult"); - else if (c == UNORDERED) - fprintf (file, "un"); - else - fprintf (file, "%s", GET_RTX_NAME (c)); - } - break; - - case 'E': - /* Write the divide or modulus operator. */ - switch (GET_CODE (x)) - { - case DIV: - fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q"); - break; - case UDIV: - fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q"); - break; - case MOD: - fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q"); - break; - case UMOD: - fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q"); - break; - default: - output_operand_lossage ("invalid %%E value"); - break; - } - break; - - case 'A': - /* Write "_u" for unaligned access. */ - if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND) - fprintf (file, "_u"); - break; - - case 0: - if (GET_CODE (x) == REG) - fprintf (file, "%s", reg_names[REGNO (x)]); - else if (GET_CODE (x) == MEM) - output_address (XEXP (x, 0)); - else if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == UNSPEC) - { - switch (XINT (XEXP (x, 0), 1)) - { - case UNSPEC_DTPREL: - case UNSPEC_TPREL: - output_addr_const (file, XVECEXP (XEXP (x, 0), 0, 0)); - break; - default: - output_operand_lossage ("unknown relocation unspec"); - break; - } - } - else - output_addr_const (file, x); - break; - - default: - output_operand_lossage ("invalid %%xn code"); - } -} - -void -print_operand_address (FILE *file, rtx addr) -{ - int basereg = 31; - HOST_WIDE_INT offset = 0; - - if (GET_CODE (addr) == AND) - addr = XEXP (addr, 0); - - if (GET_CODE (addr) == PLUS - && GET_CODE (XEXP (addr, 1)) == CONST_INT) - { - offset = INTVAL (XEXP (addr, 1)); - addr = XEXP (addr, 0); - } - - if (GET_CODE (addr) == LO_SUM) - { - const char *reloc16, *reloclo; - rtx op1 = XEXP (addr, 1); - - if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1, 0)) == UNSPEC) - { - op1 = XEXP (op1, 0); - switch (XINT (op1, 1)) - { - case UNSPEC_DTPREL: - reloc16 = NULL; - reloclo = (alpha_tls_size == 16 ? "dtprel" : "dtprello"); - break; - case UNSPEC_TPREL: - reloc16 = NULL; - reloclo = (alpha_tls_size == 16 ? "tprel" : "tprello"); - break; - default: - output_operand_lossage ("unknown relocation unspec"); - return; - } - - output_addr_const (file, XVECEXP (op1, 0, 0)); - } - else - { - reloc16 = "gprel"; - reloclo = "gprellow"; - output_addr_const (file, op1); - } - - if (offset) - fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset); - - addr = XEXP (addr, 0); - if (GET_CODE (addr) == REG) - basereg = REGNO (addr); - else if (GET_CODE (addr) == SUBREG - && GET_CODE (SUBREG_REG (addr)) == REG) - basereg = subreg_regno (addr); - else - abort (); - - fprintf (file, "($%d)\t\t!%s", basereg, - (basereg == 29 ? reloc16 : reloclo)); - return; - } - - if (GET_CODE (addr) == REG) - basereg = REGNO (addr); - else if (GET_CODE (addr) == SUBREG - && GET_CODE (SUBREG_REG (addr)) == REG) - basereg = subreg_regno (addr); - else if (GET_CODE (addr) == CONST_INT) - offset = INTVAL (addr); - -#if TARGET_ABI_OPEN_VMS - else if (GET_CODE (addr) == SYMBOL_REF) - { - fprintf (file, "%s", XSTR (addr, 0)); - return; - } - else if (GET_CODE (addr) == CONST - && GET_CODE (XEXP (addr, 0)) == PLUS - && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF) - { - fprintf (file, "%s+" HOST_WIDE_INT_PRINT_DEC, - XSTR (XEXP (XEXP (addr, 0), 0), 0), - INTVAL (XEXP (XEXP (addr, 0), 1))); - return; - } -#endif - - else - abort (); - - fprintf (file, HOST_WIDE_INT_PRINT_DEC "($%d)", offset, basereg); -} - -/* Emit RTL insns to initialize the variable parts of a trampoline at - TRAMP. FNADDR is an RTX for the address of the function's pure - code. CXT is an RTX for the static chain value for the function. - - The three offset parameters are for the individual template's - layout. A JMPOFS < 0 indicates that the trampoline does not - contain instructions at all. - - We assume here that a function will be called many more times than - its address is taken (e.g., it might be passed to qsort), so we - take the trouble to initialize the "hint" field in the JMP insn. - Note that the hint field is PC (new) + 4 * bits 13:0. */ - -void -alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt, - int fnofs, int cxtofs, int jmpofs) -{ - rtx temp, temp1, addr; - /* VMS really uses DImode pointers in memory at this point. */ - enum machine_mode mode = TARGET_ABI_OPEN_VMS ? Pmode : ptr_mode; - -#ifdef POINTERS_EXTEND_UNSIGNED - fnaddr = convert_memory_address (mode, fnaddr); - cxt = convert_memory_address (mode, cxt); -#endif - - /* Store function address and CXT. */ - addr = memory_address (mode, plus_constant (tramp, fnofs)); - emit_move_insn (gen_rtx_MEM (mode, addr), fnaddr); - addr = memory_address (mode, plus_constant (tramp, cxtofs)); - emit_move_insn (gen_rtx_MEM (mode, addr), cxt); - - /* This has been disabled since the hint only has a 32k range, and in - no existing OS is the stack within 32k of the text segment. */ - if (0 && jmpofs >= 0) - { - /* Compute hint value. */ - temp = force_operand (plus_constant (tramp, jmpofs+4), NULL_RTX); - temp = expand_binop (DImode, sub_optab, fnaddr, temp, temp, 1, - OPTAB_WIDEN); - temp = expand_shift (RSHIFT_EXPR, Pmode, temp, - build_int_2 (2, 0), NULL_RTX, 1); - temp = expand_and (SImode, gen_lowpart (SImode, temp), - GEN_INT (0x3fff), 0); - - /* Merge in the hint. */ - addr = memory_address (SImode, plus_constant (tramp, jmpofs)); - temp1 = force_reg (SImode, gen_rtx_MEM (SImode, addr)); - temp1 = expand_and (SImode, temp1, GEN_INT (0xffffc000), NULL_RTX); - temp1 = expand_binop (SImode, ior_optab, temp1, temp, temp1, 1, - OPTAB_WIDEN); - emit_move_insn (gen_rtx_MEM (SImode, addr), temp1); - } - -#ifdef ENABLE_EXECUTE_STACK - emit_library_call (init_one_libfunc ("__enable_execute_stack"), - 0, VOIDmode, 1, tramp, Pmode); -#endif - - if (jmpofs >= 0) - emit_insn (gen_imb ()); -} - -/* Determine where to put an argument to a function. - Value is zero to push the argument on the stack, - or a hard register in which to store the argument. - - MODE is the argument's machine mode. - TYPE is the data type of the argument (as a tree). - This is null for libcalls where that information may - not be available. - CUM is a variable of type CUMULATIVE_ARGS which gives info about - the preceding args and about the function being called. - NAMED is nonzero if this argument is a named parameter - (otherwise it is an extra parameter matching an ellipsis). - - On Alpha the first 6 words of args are normally in registers - and the rest are pushed. */ - -rtx -function_arg (CUMULATIVE_ARGS cum, enum machine_mode mode, tree type, - int named ATTRIBUTE_UNUSED) -{ - int basereg; - int num_args; - - /* Don't get confused and pass small structures in FP registers. */ - if (type && AGGREGATE_TYPE_P (type)) - basereg = 16; - else - { -#ifdef ENABLE_CHECKING - /* With alpha_split_complex_arg, we shouldn't see any raw complex - values here. */ - if (COMPLEX_MODE_P (mode)) - abort (); -#endif - - /* Set up defaults for FP operands passed in FP registers, and - integral operands passed in integer registers. */ - if (TARGET_FPREGS && GET_MODE_CLASS (mode) == MODE_FLOAT) - basereg = 32 + 16; - else - basereg = 16; - } - - /* ??? Irritatingly, the definition of CUMULATIVE_ARGS is different for - the three platforms, so we can't avoid conditional compilation. */ -#if TARGET_ABI_OPEN_VMS - { - if (mode == VOIDmode) - return alpha_arg_info_reg_val (cum); - - num_args = cum.num_args; - if (num_args >= 6 || MUST_PASS_IN_STACK (mode, type)) - return NULL_RTX; - } -#elif TARGET_ABI_UNICOSMK - { - int size; - - /* If this is the last argument, generate the call info word (CIW). */ - /* ??? We don't include the caller's line number in the CIW because - I don't know how to determine it if debug infos are turned off. */ - if (mode == VOIDmode) - { - int i; - HOST_WIDE_INT lo; - HOST_WIDE_INT hi; - rtx ciw; - - lo = 0; - - for (i = 0; i < cum.num_reg_words && i < 5; i++) - if (cum.reg_args_type[i]) - lo |= (1 << (7 - i)); - - if (cum.num_reg_words == 6 && cum.reg_args_type[5]) - lo |= 7; - else - lo |= cum.num_reg_words; - -#if HOST_BITS_PER_WIDE_INT == 32 - hi = (cum.num_args << 20) | cum.num_arg_words; -#else - lo = lo | ((HOST_WIDE_INT) cum.num_args << 52) - | ((HOST_WIDE_INT) cum.num_arg_words << 32); - hi = 0; -#endif - ciw = immed_double_const (lo, hi, DImode); - - return gen_rtx_UNSPEC (DImode, gen_rtvec (1, ciw), - UNSPEC_UMK_LOAD_CIW); - } - - size = ALPHA_ARG_SIZE (mode, type, named); - num_args = cum.num_reg_words; - if (MUST_PASS_IN_STACK (mode, type) - || cum.num_reg_words + size > 6 || cum.force_stack) - return NULL_RTX; - else if (type && TYPE_MODE (type) == BLKmode) - { - rtx reg1, reg2; - - reg1 = gen_rtx_REG (DImode, num_args + 16); - reg1 = gen_rtx_EXPR_LIST (DImode, reg1, const0_rtx); - - /* The argument fits in two registers. Note that we still need to - reserve a register for empty structures. */ - if (size == 0) - return NULL_RTX; - else if (size == 1) - return gen_rtx_PARALLEL (mode, gen_rtvec (1, reg1)); - else - { - reg2 = gen_rtx_REG (DImode, num_args + 17); - reg2 = gen_rtx_EXPR_LIST (DImode, reg2, GEN_INT (8)); - return gen_rtx_PARALLEL (mode, gen_rtvec (2, reg1, reg2)); - } - } - } -#elif TARGET_ABI_OSF - { - if (cum >= 6) - return NULL_RTX; - num_args = cum; - - /* VOID is passed as a special flag for "last argument". */ - if (type == void_type_node) - basereg = 16; - else if (MUST_PASS_IN_STACK (mode, type)) - return NULL_RTX; - else if (FUNCTION_ARG_PASS_BY_REFERENCE (cum, mode, type, named)) - basereg = 16; - } -#else -#error Unhandled ABI -#endif - - return gen_rtx_REG (mode, num_args + basereg); -} - -/* Return true if TYPE must be returned in memory, instead of in registers. */ - -static bool -alpha_return_in_memory (tree type, tree fndecl ATTRIBUTE_UNUSED) -{ - enum machine_mode mode = VOIDmode; - int size; - - if (type) - { - mode = TYPE_MODE (type); - - /* All aggregates are returned in memory. */ - if (AGGREGATE_TYPE_P (type)) - return true; - } - - size = GET_MODE_SIZE (mode); - switch (GET_MODE_CLASS (mode)) - { - case MODE_VECTOR_FLOAT: - /* Pass all float vectors in memory, like an aggregate. */ - return true; - - case MODE_COMPLEX_FLOAT: - /* We judge complex floats on the size of their element, - not the size of the whole type. */ - size = GET_MODE_UNIT_SIZE (mode); - break; - - case MODE_INT: - case MODE_FLOAT: - case MODE_COMPLEX_INT: - case MODE_VECTOR_INT: - break; - - default: - /* ??? We get called on all sorts of random stuff from - aggregate_value_p. We can't abort, but it's not clear - what's safe to return. Pretend it's a struct I guess. */ - return true; - } - - /* Otherwise types must fit in one register. */ - return size > UNITS_PER_WORD; -} - -/* Define how to find the value returned by a function. VALTYPE is the - data type of the value (as a tree). If the precise function being - called is known, FUNC is its FUNCTION_DECL; otherwise, FUNC is 0. - MODE is set instead of VALTYPE for libcalls. - - On Alpha the value is found in $0 for integer functions and - $f0 for floating-point functions. */ - -rtx -function_value (tree valtype, tree func ATTRIBUTE_UNUSED, - enum machine_mode mode) -{ - unsigned int regnum; - enum mode_class class; - -#ifdef ENABLE_CHECKING - if (valtype && alpha_return_in_memory (valtype, func)) - abort (); -#endif - - if (valtype) - mode = TYPE_MODE (valtype); - - class = GET_MODE_CLASS (mode); - switch (class) - { - case MODE_INT: - /* Do the same thing as PROMOTE_MODE. */ - mode = DImode; - /* FALLTHRU */ - - case MODE_COMPLEX_INT: - case MODE_VECTOR_INT: - regnum = 0; - break; - - case MODE_FLOAT: - regnum = 32; - break; - - case MODE_COMPLEX_FLOAT: - { - enum machine_mode cmode = GET_MODE_INNER (mode); - - return gen_rtx_PARALLEL - (VOIDmode, - gen_rtvec (2, - gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 32), - GEN_INT (0)), - gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 33), - GEN_INT (GET_MODE_SIZE (cmode))))); - } - - default: - abort (); - } - - return gen_rtx_REG (mode, regnum); -} - -/* TCmode complex values are passed by invisible reference. We - should not split these values. */ - -static bool -alpha_split_complex_arg (tree type) -{ - return TYPE_MODE (type) != TCmode; -} - -static tree -alpha_build_builtin_va_list (void) -{ - tree base, ofs, space, record, type_decl; - - if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK) - return ptr_type_node; - - record = (*lang_hooks.types.make_type) (RECORD_TYPE); - type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); - TREE_CHAIN (record) = type_decl; - TYPE_NAME (record) = type_decl; - - /* C++? SET_IS_AGGR_TYPE (record, 1); */ - - /* Dummy field to prevent alignment warnings. */ - space = build_decl (FIELD_DECL, NULL_TREE, integer_type_node); - DECL_FIELD_CONTEXT (space) = record; - DECL_ARTIFICIAL (space) = 1; - DECL_IGNORED_P (space) = 1; - - ofs = build_decl (FIELD_DECL, get_identifier ("__offset"), - integer_type_node); - DECL_FIELD_CONTEXT (ofs) = record; - TREE_CHAIN (ofs) = space; - - base = build_decl (FIELD_DECL, get_identifier ("__base"), - ptr_type_node); - DECL_FIELD_CONTEXT (base) = record; - TREE_CHAIN (base) = ofs; - - TYPE_FIELDS (record) = base; - layout_type (record); - - return record; -} - -/* Perform any needed actions needed for a function that is receiving a - variable number of arguments. */ - -static void -alpha_setup_incoming_varargs (CUMULATIVE_ARGS *pcum, - enum machine_mode mode ATTRIBUTE_UNUSED, - tree type ATTRIBUTE_UNUSED, - int *pretend_size, int no_rtl) -{ -#if TARGET_ABI_UNICOSMK - /* On Unicos/Mk, the standard subroutine __T3E_MISMATCH stores all register - arguments on the stack. Unfortunately, it doesn't always store the first - one (i.e. the one that arrives in $16 or $f16). This is not a problem - with stdargs as we always have at least one named argument there. */ - int num_reg_words = pcum->num_reg_words; - if (num_reg_words < 6) - { - if (!no_rtl) - { - emit_insn (gen_umk_mismatch_args (GEN_INT (num_reg_words + 1))); - emit_insn (gen_arg_home_umk ()); - } - *pretend_size = 0; - } -#elif TARGET_ABI_OPEN_VMS - /* For VMS, we allocate space for all 6 arg registers plus a count. - - However, if NO registers need to be saved, don't allocate any space. - This is not only because we won't need the space, but because AP - includes the current_pretend_args_size and we don't want to mess up - any ap-relative addresses already made. */ - if (pcum->num_args < 6) - { - if (!no_rtl) - { - emit_move_insn (gen_rtx_REG (DImode, 1), virtual_incoming_args_rtx); - emit_insn (gen_arg_home ()); - } - *pretend_size = 7 * UNITS_PER_WORD; - } -#else - /* On OSF/1 and friends, we allocate space for all 12 arg registers, but - only push those that are remaining. However, if NO registers need to - be saved, don't allocate any space. This is not only because we won't - need the space, but because AP includes the current_pretend_args_size - and we don't want to mess up any ap-relative addresses already made. - - If we are not to use the floating-point registers, save the integer - registers where we would put the floating-point registers. This is - not the most efficient way to implement varargs with just one register - class, but it isn't worth doing anything more efficient in this rare - case. */ - CUMULATIVE_ARGS cum = *pcum; - - if (cum >= 6) - return; - - if (!no_rtl) - { - int set = get_varargs_alias_set (); - rtx tmp; - - tmp = gen_rtx_MEM (BLKmode, - plus_constant (virtual_incoming_args_rtx, - (cum + 6) * UNITS_PER_WORD)); - set_mem_alias_set (tmp, set); - move_block_from_reg (16 + cum, tmp, 6 - cum); - - tmp = gen_rtx_MEM (BLKmode, - plus_constant (virtual_incoming_args_rtx, - cum * UNITS_PER_WORD)); - set_mem_alias_set (tmp, set); - move_block_from_reg (16 + (TARGET_FPREGS ? 32 : 0) + cum, tmp, - 6 - cum); - } - *pretend_size = 12 * UNITS_PER_WORD; -#endif -} - -void -alpha_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED) -{ - HOST_WIDE_INT offset; - tree t, offset_field, base_field; - - if (TREE_CODE (TREE_TYPE (valist)) == ERROR_MARK) - return; - - if (TARGET_ABI_UNICOSMK) - std_expand_builtin_va_start (valist, nextarg); - - /* For Unix, SETUP_INCOMING_VARARGS moves the starting address base - up by 48, storing fp arg registers in the first 48 bytes, and the - integer arg registers in the next 48 bytes. This is only done, - however, if any integer registers need to be stored. - - If no integer registers need be stored, then we must subtract 48 - in order to account for the integer arg registers which are counted - in argsize above, but which are not actually stored on the stack. - Must further be careful here about structures straddling the last - integer argument register; that futzes with pretend_args_size, - which changes the meaning of AP. */ - - if (NUM_ARGS <= 6) - offset = TARGET_ABI_OPEN_VMS ? UNITS_PER_WORD : 6 * UNITS_PER_WORD; - else - offset = -6 * UNITS_PER_WORD + current_function_pretend_args_size; - - if (TARGET_ABI_OPEN_VMS) - { - nextarg = plus_constant (nextarg, offset); - nextarg = plus_constant (nextarg, NUM_ARGS * UNITS_PER_WORD); - t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, - make_tree (ptr_type_node, nextarg)); - TREE_SIDE_EFFECTS (t) = 1; - - expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); - } - else - { - base_field = TYPE_FIELDS (TREE_TYPE (valist)); - offset_field = TREE_CHAIN (base_field); - - base_field = build (COMPONENT_REF, TREE_TYPE (base_field), - valist, base_field); - offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field), - valist, offset_field); - - t = make_tree (ptr_type_node, virtual_incoming_args_rtx); - t = build (PLUS_EXPR, ptr_type_node, t, build_int_2 (offset, 0)); - t = build (MODIFY_EXPR, TREE_TYPE (base_field), base_field, t); - TREE_SIDE_EFFECTS (t) = 1; - expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); - - t = build_int_2 (NUM_ARGS * UNITS_PER_WORD, 0); - t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, t); - TREE_SIDE_EFFECTS (t) = 1; - expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); - } -} - -rtx -alpha_va_arg (tree valist, tree type) -{ - rtx addr; - tree t, type_size, rounded_size; - tree offset_field, base_field, addr_tree, addend; - tree wide_type, wide_ofs; - int indirect = 0; - - if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK) - return std_expand_builtin_va_arg (valist, type); - - if (type == error_mark_node - || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL - || TREE_OVERFLOW (type_size)) - rounded_size = size_zero_node; - else - rounded_size = fold (build (MULT_EXPR, sizetype, - fold (build (TRUNC_DIV_EXPR, sizetype, - fold (build (PLUS_EXPR, sizetype, - type_size, - size_int (7))), - size_int (8))), - size_int (8))); - - base_field = TYPE_FIELDS (TREE_TYPE (valist)); - offset_field = TREE_CHAIN (base_field); - - base_field = build (COMPONENT_REF, TREE_TYPE (base_field), - valist, base_field); - offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field), - valist, offset_field); - - /* If the type could not be passed in registers, skip the block - reserved for the registers. */ - if (MUST_PASS_IN_STACK (TYPE_MODE (type), type)) - { - t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, - build (MAX_EXPR, TREE_TYPE (offset_field), - offset_field, build_int_2 (6*8, 0))); - TREE_SIDE_EFFECTS (t) = 1; - expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); - } - - wide_type = make_signed_type (64); - wide_ofs = save_expr (build1 (CONVERT_EXPR, wide_type, offset_field)); - - addend = wide_ofs; - - if (TYPE_MODE (type) == TFmode || TYPE_MODE (type) == TCmode) - { - indirect = 1; - rounded_size = size_int (UNITS_PER_WORD); - } - else if (TREE_CODE (type) == COMPLEX_TYPE) - { - rtx real_part, imag_part, value, tmp; - - real_part = alpha_va_arg (valist, TREE_TYPE (type)); - imag_part = alpha_va_arg (valist, TREE_TYPE (type)); - - /* ??? Most irritatingly, we're not returning the value here, - but the address. Since real_part and imag_part are not - necessarily contiguous, we must copy to local storage. */ - - real_part = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (type)), real_part); - imag_part = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (type)), imag_part); - value = gen_rtx_CONCAT (TYPE_MODE (type), real_part, imag_part); - - tmp = assign_temp (type, 0, 1, 0); - emit_move_insn (tmp, value); - - return XEXP (tmp, 0); - } - else if (TREE_CODE (type) == REAL_TYPE) - { - tree fpaddend, cond; - - fpaddend = fold (build (PLUS_EXPR, TREE_TYPE (addend), - addend, build_int_2 (-6*8, 0))); - - cond = fold (build (LT_EXPR, integer_type_node, - wide_ofs, build_int_2 (6*8, 0))); - - addend = fold (build (COND_EXPR, TREE_TYPE (addend), cond, - fpaddend, addend)); - } - - addr_tree = build (PLUS_EXPR, TREE_TYPE (base_field), - base_field, addend); - - addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL); - addr = copy_to_reg (addr); - - t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, - build (PLUS_EXPR, TREE_TYPE (offset_field), - offset_field, rounded_size)); - TREE_SIDE_EFFECTS (t) = 1; - expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); - - if (indirect) - { - addr = force_reg (Pmode, addr); - addr = gen_rtx_MEM (Pmode, addr); - } - - return addr; -} - -/* Builtins. */ - -enum alpha_builtin -{ - ALPHA_BUILTIN_CMPBGE, - ALPHA_BUILTIN_EXTBL, - ALPHA_BUILTIN_EXTWL, - ALPHA_BUILTIN_EXTLL, - ALPHA_BUILTIN_EXTQL, - ALPHA_BUILTIN_EXTWH, - ALPHA_BUILTIN_EXTLH, - ALPHA_BUILTIN_EXTQH, - ALPHA_BUILTIN_INSBL, - ALPHA_BUILTIN_INSWL, - ALPHA_BUILTIN_INSLL, - ALPHA_BUILTIN_INSQL, - ALPHA_BUILTIN_INSWH, - ALPHA_BUILTIN_INSLH, - ALPHA_BUILTIN_INSQH, - ALPHA_BUILTIN_MSKBL, - ALPHA_BUILTIN_MSKWL, - ALPHA_BUILTIN_MSKLL, - ALPHA_BUILTIN_MSKQL, - ALPHA_BUILTIN_MSKWH, - ALPHA_BUILTIN_MSKLH, - ALPHA_BUILTIN_MSKQH, - ALPHA_BUILTIN_UMULH, - ALPHA_BUILTIN_ZAP, - ALPHA_BUILTIN_ZAPNOT, - ALPHA_BUILTIN_AMASK, - ALPHA_BUILTIN_IMPLVER, - ALPHA_BUILTIN_RPCC, - ALPHA_BUILTIN_THREAD_POINTER, - ALPHA_BUILTIN_SET_THREAD_POINTER, - - /* TARGET_MAX */ - ALPHA_BUILTIN_MINUB8, - ALPHA_BUILTIN_MINSB8, - ALPHA_BUILTIN_MINUW4, - ALPHA_BUILTIN_MINSW4, - ALPHA_BUILTIN_MAXUB8, - ALPHA_BUILTIN_MAXSB8, - ALPHA_BUILTIN_MAXUW4, - ALPHA_BUILTIN_MAXSW4, - ALPHA_BUILTIN_PERR, - ALPHA_BUILTIN_PKLB, - ALPHA_BUILTIN_PKWB, - ALPHA_BUILTIN_UNPKBL, - ALPHA_BUILTIN_UNPKBW, - - /* TARGET_CIX */ - ALPHA_BUILTIN_CTTZ, - ALPHA_BUILTIN_CTLZ, - ALPHA_BUILTIN_CTPOP, - - ALPHA_BUILTIN_max -}; - -static unsigned int const code_for_builtin[ALPHA_BUILTIN_max] = { - CODE_FOR_builtin_cmpbge, - CODE_FOR_builtin_extbl, - CODE_FOR_builtin_extwl, - CODE_FOR_builtin_extll, - CODE_FOR_builtin_extql, - CODE_FOR_builtin_extwh, - CODE_FOR_builtin_extlh, - CODE_FOR_builtin_extqh, - CODE_FOR_builtin_insbl, - CODE_FOR_builtin_inswl, - CODE_FOR_builtin_insll, - CODE_FOR_builtin_insql, - CODE_FOR_builtin_inswh, - CODE_FOR_builtin_inslh, - CODE_FOR_builtin_insqh, - CODE_FOR_builtin_mskbl, - CODE_FOR_builtin_mskwl, - CODE_FOR_builtin_mskll, - CODE_FOR_builtin_mskql, - CODE_FOR_builtin_mskwh, - CODE_FOR_builtin_msklh, - CODE_FOR_builtin_mskqh, - CODE_FOR_umuldi3_highpart, - CODE_FOR_builtin_zap, - CODE_FOR_builtin_zapnot, - CODE_FOR_builtin_amask, - CODE_FOR_builtin_implver, - CODE_FOR_builtin_rpcc, - CODE_FOR_load_tp, - CODE_FOR_set_tp, - - /* TARGET_MAX */ - CODE_FOR_builtin_minub8, - CODE_FOR_builtin_minsb8, - CODE_FOR_builtin_minuw4, - CODE_FOR_builtin_minsw4, - CODE_FOR_builtin_maxub8, - CODE_FOR_builtin_maxsb8, - CODE_FOR_builtin_maxuw4, - CODE_FOR_builtin_maxsw4, - CODE_FOR_builtin_perr, - CODE_FOR_builtin_pklb, - CODE_FOR_builtin_pkwb, - CODE_FOR_builtin_unpkbl, - CODE_FOR_builtin_unpkbw, - - /* TARGET_CIX */ - CODE_FOR_builtin_cttz, - CODE_FOR_builtin_ctlz, - CODE_FOR_builtin_ctpop -}; - -struct alpha_builtin_def -{ - const char *name; - enum alpha_builtin code; - unsigned int target_mask; -}; - -static struct alpha_builtin_def const zero_arg_builtins[] = { - { "__builtin_alpha_implver", ALPHA_BUILTIN_IMPLVER, 0 }, - { "__builtin_alpha_rpcc", ALPHA_BUILTIN_RPCC, 0 } -}; - -static struct alpha_builtin_def const one_arg_builtins[] = { - { "__builtin_alpha_amask", ALPHA_BUILTIN_AMASK, 0 }, - { "__builtin_alpha_pklb", ALPHA_BUILTIN_PKLB, MASK_MAX }, - { "__builtin_alpha_pkwb", ALPHA_BUILTIN_PKWB, MASK_MAX }, - { "__builtin_alpha_unpkbl", ALPHA_BUILTIN_UNPKBL, MASK_MAX }, - { "__builtin_alpha_unpkbw", ALPHA_BUILTIN_UNPKBW, MASK_MAX }, - { "__builtin_alpha_cttz", ALPHA_BUILTIN_CTTZ, MASK_CIX }, - { "__builtin_alpha_ctlz", ALPHA_BUILTIN_CTLZ, MASK_CIX }, - { "__builtin_alpha_ctpop", ALPHA_BUILTIN_CTPOP, MASK_CIX } -}; - -static struct alpha_builtin_def const two_arg_builtins[] = { - { "__builtin_alpha_cmpbge", ALPHA_BUILTIN_CMPBGE, 0 }, - { "__builtin_alpha_extbl", ALPHA_BUILTIN_EXTBL, 0 }, - { "__builtin_alpha_extwl", ALPHA_BUILTIN_EXTWL, 0 }, - { "__builtin_alpha_extll", ALPHA_BUILTIN_EXTLL, 0 }, - { "__builtin_alpha_extql", ALPHA_BUILTIN_EXTQL, 0 }, - { "__builtin_alpha_extwh", ALPHA_BUILTIN_EXTWH, 0 }, - { "__builtin_alpha_extlh", ALPHA_BUILTIN_EXTLH, 0 }, - { "__builtin_alpha_extqh", ALPHA_BUILTIN_EXTQH, 0 }, - { "__builtin_alpha_insbl", ALPHA_BUILTIN_INSBL, 0 }, - { "__builtin_alpha_inswl", ALPHA_BUILTIN_INSWL, 0 }, - { "__builtin_alpha_insll", ALPHA_BUILTIN_INSLL, 0 }, - { "__builtin_alpha_insql", ALPHA_BUILTIN_INSQL, 0 }, - { "__builtin_alpha_inswh", ALPHA_BUILTIN_INSWH, 0 }, - { "__builtin_alpha_inslh", ALPHA_BUILTIN_INSLH, 0 }, - { "__builtin_alpha_insqh", ALPHA_BUILTIN_INSQH, 0 }, - { "__builtin_alpha_mskbl", ALPHA_BUILTIN_MSKBL, 0 }, - { "__builtin_alpha_mskwl", ALPHA_BUILTIN_MSKWL, 0 }, - { "__builtin_alpha_mskll", ALPHA_BUILTIN_MSKLL, 0 }, - { "__builtin_alpha_mskql", ALPHA_BUILTIN_MSKQL, 0 }, - { "__builtin_alpha_mskwh", ALPHA_BUILTIN_MSKWH, 0 }, - { "__builtin_alpha_msklh", ALPHA_BUILTIN_MSKLH, 0 }, - { "__builtin_alpha_mskqh", ALPHA_BUILTIN_MSKQH, 0 }, - { "__builtin_alpha_umulh", ALPHA_BUILTIN_UMULH, 0 }, - { "__builtin_alpha_zap", ALPHA_BUILTIN_ZAP, 0 }, - { "__builtin_alpha_zapnot", ALPHA_BUILTIN_ZAPNOT, 0 }, - { "__builtin_alpha_minub8", ALPHA_BUILTIN_MINUB8, MASK_MAX }, - { "__builtin_alpha_minsb8", ALPHA_BUILTIN_MINSB8, MASK_MAX }, - { "__builtin_alpha_minuw4", ALPHA_BUILTIN_MINUW4, MASK_MAX }, - { "__builtin_alpha_minsw4", ALPHA_BUILTIN_MINSW4, MASK_MAX }, - { "__builtin_alpha_maxub8", ALPHA_BUILTIN_MAXUB8, MASK_MAX }, - { "__builtin_alpha_maxsb8", ALPHA_BUILTIN_MAXSB8, MASK_MAX }, - { "__builtin_alpha_maxuw4", ALPHA_BUILTIN_MAXUW4, MASK_MAX }, - { "__builtin_alpha_maxsw4", ALPHA_BUILTIN_MAXSW4, MASK_MAX }, - { "__builtin_alpha_perr", ALPHA_BUILTIN_PERR, MASK_MAX } -}; - -static void -alpha_init_builtins (void) -{ - const struct alpha_builtin_def *p; - tree ftype; - size_t i; - - ftype = build_function_type (long_integer_type_node, void_list_node); - - p = zero_arg_builtins; - for (i = 0; i < ARRAY_SIZE (zero_arg_builtins); ++i, ++p) - if ((target_flags & p->target_mask) == p->target_mask) - builtin_function (p->name, ftype, p->code, BUILT_IN_MD, - NULL, NULL_TREE); - - ftype = build_function_type_list (long_integer_type_node, - long_integer_type_node, NULL_TREE); - - p = one_arg_builtins; - for (i = 0; i < ARRAY_SIZE (one_arg_builtins); ++i, ++p) - if ((target_flags & p->target_mask) == p->target_mask) - builtin_function (p->name, ftype, p->code, BUILT_IN_MD, - NULL, NULL_TREE); - - ftype = build_function_type_list (long_integer_type_node, - long_integer_type_node, - long_integer_type_node, NULL_TREE); - - p = two_arg_builtins; - for (i = 0; i < ARRAY_SIZE (two_arg_builtins); ++i, ++p) - if ((target_flags & p->target_mask) == p->target_mask) - builtin_function (p->name, ftype, p->code, BUILT_IN_MD, - NULL, NULL_TREE); - - ftype = build_function_type (ptr_type_node, void_list_node); - builtin_function ("__builtin_thread_pointer", ftype, - ALPHA_BUILTIN_THREAD_POINTER, BUILT_IN_MD, - NULL, NULL_TREE); - - ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE); - builtin_function ("__builtin_set_thread_pointer", ftype, - ALPHA_BUILTIN_SET_THREAD_POINTER, BUILT_IN_MD, - NULL, NULL_TREE); -} - -/* Expand an expression EXP that calls a built-in function, - with result going to TARGET if that's convenient - (and in mode MODE if that's convenient). - SUBTARGET may be used as the target for computing one of EXP's operands. - IGNORE is nonzero if the value is to be ignored. */ - -static rtx -alpha_expand_builtin (tree exp, rtx target, - rtx subtarget ATTRIBUTE_UNUSED, - enum machine_mode mode ATTRIBUTE_UNUSED, - int ignore ATTRIBUTE_UNUSED) -{ -#define MAX_ARGS 2 - - tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); - unsigned int fcode = DECL_FUNCTION_CODE (fndecl); - tree arglist = TREE_OPERAND (exp, 1); - enum insn_code icode; - rtx op[MAX_ARGS], pat; - int arity; - bool nonvoid; - - if (fcode >= ALPHA_BUILTIN_max) - internal_error ("bad builtin fcode"); - icode = code_for_builtin[fcode]; - if (icode == 0) - internal_error ("bad builtin fcode"); - - nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node; - - for (arglist = TREE_OPERAND (exp, 1), arity = 0; - arglist; - arglist = TREE_CHAIN (arglist), arity++) - { - const struct insn_operand_data *insn_op; - - tree arg = TREE_VALUE (arglist); - if (arg == error_mark_node) - return NULL_RTX; - if (arity > MAX_ARGS) - return NULL_RTX; - - insn_op = &insn_data[icode].operand[arity + nonvoid]; - - op[arity] = expand_expr (arg, NULL_RTX, insn_op->mode, 0); - - if (!(*insn_op->predicate) (op[arity], insn_op->mode)) - op[arity] = copy_to_mode_reg (insn_op->mode, op[arity]); - } - - if (nonvoid) - { - enum machine_mode tmode = insn_data[icode].operand[0].mode; - if (!target - || GET_MODE (target) != tmode - || !(*insn_data[icode].operand[0].predicate) (target, tmode)) - target = gen_reg_rtx (tmode); - } - - switch (arity) - { - case 0: - pat = GEN_FCN (icode) (target); - break; - case 1: - if (nonvoid) - pat = GEN_FCN (icode) (target, op[0]); - else - pat = GEN_FCN (icode) (op[0]); - break; - case 2: - pat = GEN_FCN (icode) (target, op[0], op[1]); - break; - default: - abort (); - } - if (!pat) - return NULL_RTX; - emit_insn (pat); - - if (nonvoid) - return target; - else - return const0_rtx; -} - -/* This page contains routines that are used to determine what the function - prologue and epilogue code will do and write them out. */ - -/* Compute the size of the save area in the stack. */ - -/* These variables are used for communication between the following functions. - They indicate various things about the current function being compiled - that are used to tell what kind of prologue, epilogue and procedure - descriptor to generate. */ - -/* Nonzero if we need a stack procedure. */ -enum alpha_procedure_types {PT_NULL = 0, PT_REGISTER = 1, PT_STACK = 2}; -static enum alpha_procedure_types alpha_procedure_type; - -/* Register number (either FP or SP) that is used to unwind the frame. */ -static int vms_unwind_regno; - -/* Register number used to save FP. We need not have one for RA since - we don't modify it for register procedures. This is only defined - for register frame procedures. */ -static int vms_save_fp_regno; - -/* Register number used to reference objects off our PV. */ -static int vms_base_regno; - -/* Compute register masks for saved registers. */ - -static void -alpha_sa_mask (unsigned long *imaskP, unsigned long *fmaskP) -{ - unsigned long imask = 0; - unsigned long fmask = 0; - unsigned int i; - - /* When outputting a thunk, we don't have valid register life info, - but assemble_start_function wants to output .frame and .mask - directives. */ - if (current_function_is_thunk) - { - *imaskP = 0; - *fmaskP = 0; - return; - } - - if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK) - imask |= (1UL << HARD_FRAME_POINTER_REGNUM); - - /* One for every register we have to save. */ - for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) - if (! fixed_regs[i] && ! call_used_regs[i] - && regs_ever_live[i] && i != REG_RA - && (!TARGET_ABI_UNICOSMK || i != HARD_FRAME_POINTER_REGNUM)) - { - if (i < 32) - imask |= (1UL << i); - else - fmask |= (1UL << (i - 32)); - } - - /* We need to restore these for the handler. */ - if (current_function_calls_eh_return) - { - for (i = 0; ; ++i) - { - unsigned regno = EH_RETURN_DATA_REGNO (i); - if (regno == INVALID_REGNUM) - break; - imask |= 1UL << regno; - } - } - - /* If any register spilled, then spill the return address also. */ - /* ??? This is required by the Digital stack unwind specification - and isn't needed if we're doing Dwarf2 unwinding. */ - if (imask || fmask || alpha_ra_ever_killed ()) - imask |= (1UL << REG_RA); - - *imaskP = imask; - *fmaskP = fmask; -} - -int -alpha_sa_size (void) -{ - unsigned long mask[2]; - int sa_size = 0; - int i, j; - - alpha_sa_mask (&mask[0], &mask[1]); - - if (TARGET_ABI_UNICOSMK) - { - if (mask[0] || mask[1]) - sa_size = 14; - } - else - { - for (j = 0; j < 2; ++j) - for (i = 0; i < 32; ++i) - if ((mask[j] >> i) & 1) - sa_size++; - } - - if (TARGET_ABI_UNICOSMK) - { - /* We might not need to generate a frame if we don't make any calls - (including calls to __T3E_MISMATCH if this is a vararg function), - don't have any local variables which require stack slots, don't - use alloca and have not determined that we need a frame for other - reasons. */ - - alpha_procedure_type - = (sa_size || get_frame_size() != 0 - || current_function_outgoing_args_size - || current_function_stdarg || current_function_calls_alloca - || frame_pointer_needed) - ? PT_STACK : PT_REGISTER; - - /* Always reserve space for saving callee-saved registers if we - need a frame as required by the calling convention. */ - if (alpha_procedure_type == PT_STACK) - sa_size = 14; - } - else if (TARGET_ABI_OPEN_VMS) - { - /* Start by assuming we can use a register procedure if we don't - make any calls (REG_RA not used) or need to save any - registers and a stack procedure if we do. */ - if ((mask[0] >> REG_RA) & 1) - alpha_procedure_type = PT_STACK; - else if (get_frame_size() != 0) - alpha_procedure_type = PT_REGISTER; - else - alpha_procedure_type = PT_NULL; - - /* Don't reserve space for saving FP & RA yet. Do that later after we've - made the final decision on stack procedure vs register procedure. */ - if (alpha_procedure_type == PT_STACK) - sa_size -= 2; - - /* Decide whether to refer to objects off our PV via FP or PV. - If we need FP for something else or if we receive a nonlocal - goto (which expects PV to contain the value), we must use PV. - Otherwise, start by assuming we can use FP. */ - - vms_base_regno - = (frame_pointer_needed - || current_function_has_nonlocal_label - || alpha_procedure_type == PT_STACK - || current_function_outgoing_args_size) - ? REG_PV : HARD_FRAME_POINTER_REGNUM; - - /* If we want to copy PV into FP, we need to find some register - in which to save FP. */ - - vms_save_fp_regno = -1; - if (vms_base_regno == HARD_FRAME_POINTER_REGNUM) - for (i = 0; i < 32; i++) - if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i]) - vms_save_fp_regno = i; - - if (vms_save_fp_regno == -1 && alpha_procedure_type == PT_REGISTER) - vms_base_regno = REG_PV, alpha_procedure_type = PT_STACK; - else if (alpha_procedure_type == PT_NULL) - vms_base_regno = REG_PV; - - /* Stack unwinding should be done via FP unless we use it for PV. */ - vms_unwind_regno = (vms_base_regno == REG_PV - ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); - - /* If this is a stack procedure, allow space for saving FP and RA. */ - if (alpha_procedure_type == PT_STACK) - sa_size += 2; - } - else - { - /* Our size must be even (multiple of 16 bytes). */ - if (sa_size & 1) - sa_size++; - } - - return sa_size * 8; -} - -/* Define the offset between two registers, one to be eliminated, - and the other its replacement, at the start of a routine. */ - -HOST_WIDE_INT -alpha_initial_elimination_offset (unsigned int from, - unsigned int to ATTRIBUTE_UNUSED) -{ - HOST_WIDE_INT ret; - - ret = alpha_sa_size (); - ret += ALPHA_ROUND (current_function_outgoing_args_size); - - if (from == FRAME_POINTER_REGNUM) - ; - else if (from == ARG_POINTER_REGNUM) - ret += (ALPHA_ROUND (get_frame_size () - + current_function_pretend_args_size) - - current_function_pretend_args_size); - else - abort (); - - return ret; -} - -int -alpha_pv_save_size (void) -{ - alpha_sa_size (); - return alpha_procedure_type == PT_STACK ? 8 : 0; -} - -int -alpha_using_fp (void) -{ - alpha_sa_size (); - return vms_unwind_regno == HARD_FRAME_POINTER_REGNUM; -} - -#if TARGET_ABI_OPEN_VMS - -const struct attribute_spec vms_attribute_table[] = -{ - /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ - { "overlaid", 0, 0, true, false, false, NULL }, - { "global", 0, 0, true, false, false, NULL }, - { "initialize", 0, 0, true, false, false, NULL }, - { NULL, 0, 0, false, false, false, NULL } -}; - -#endif - -static int -find_lo_sum_using_gp (rtx *px, void *data ATTRIBUTE_UNUSED) -{ - return GET_CODE (*px) == LO_SUM && XEXP (*px, 0) == pic_offset_table_rtx; -} - -int -alpha_find_lo_sum_using_gp (rtx insn) -{ - return for_each_rtx (&PATTERN (insn), find_lo_sum_using_gp, NULL) > 0; -} - -static int -alpha_does_function_need_gp (void) -{ - rtx insn; - - /* The GP being variable is an OSF abi thing. */ - if (! TARGET_ABI_OSF) - return 0; - - /* We need the gp to load the address of __mcount. */ - if (TARGET_PROFILING_NEEDS_GP && current_function_profile) - return 1; - - /* The code emitted by alpha_output_mi_thunk_osf uses the gp. */ - if (current_function_is_thunk) - return 1; - - /* The nonlocal receiver pattern assumes that the gp is valid for - the nested function. Reasonable because it's almost always set - correctly already. For the cases where that's wrong, make sure - the nested function loads its gp on entry. */ - if (current_function_has_nonlocal_goto) - return 1; - - /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. - Even if we are a static function, we still need to do this in case - our address is taken and passed to something like qsort. */ - - push_topmost_sequence (); - insn = get_insns (); - pop_topmost_sequence (); - - for (; insn; insn = NEXT_INSN (insn)) - if (INSN_P (insn) - && GET_CODE (PATTERN (insn)) != USE - && GET_CODE (PATTERN (insn)) != CLOBBER - && get_attr_usegp (insn)) - return 1; - - return 0; -} - - -/* Helper function to set RTX_FRAME_RELATED_P on instructions, including - sequences. */ - -static rtx -set_frame_related_p (void) -{ - rtx seq = get_insns (); - rtx insn; - - end_sequence (); - - if (!seq) - return NULL_RTX; - - if (INSN_P (seq)) - { - insn = seq; - while (insn != NULL_RTX) - { - RTX_FRAME_RELATED_P (insn) = 1; - insn = NEXT_INSN (insn); - } - seq = emit_insn (seq); - } - else - { - seq = emit_insn (seq); - RTX_FRAME_RELATED_P (seq) = 1; - } - return seq; -} - -#define FRP(exp) (start_sequence (), exp, set_frame_related_p ()) - -/* Generates a store with the proper unwind info attached. VALUE is - stored at BASE_REG+BASE_OFS. If FRAME_BIAS is non-zero, then BASE_REG - contains SP+FRAME_BIAS, and that is the unwind info that should be - generated. If FRAME_REG != VALUE, then VALUE is being stored on - behalf of FRAME_REG, and FRAME_REG should be present in the unwind. */ - -static void -emit_frame_store_1 (rtx value, rtx base_reg, HOST_WIDE_INT frame_bias, - HOST_WIDE_INT base_ofs, rtx frame_reg) -{ - rtx addr, mem, insn; - - addr = plus_constant (base_reg, base_ofs); - mem = gen_rtx_MEM (DImode, addr); - set_mem_alias_set (mem, alpha_sr_alias_set); - - insn = emit_move_insn (mem, value); - RTX_FRAME_RELATED_P (insn) = 1; - - if (frame_bias || value != frame_reg) - { - if (frame_bias) - { - addr = plus_constant (stack_pointer_rtx, frame_bias + base_ofs); - mem = gen_rtx_MEM (DImode, addr); - } - - REG_NOTES (insn) - = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, - gen_rtx_SET (VOIDmode, mem, frame_reg), - REG_NOTES (insn)); - } -} - -static void -emit_frame_store (unsigned int regno, rtx base_reg, - HOST_WIDE_INT frame_bias, HOST_WIDE_INT base_ofs) -{ - rtx reg = gen_rtx_REG (DImode, regno); - emit_frame_store_1 (reg, base_reg, frame_bias, base_ofs, reg); -} - -/* Write function prologue. */ - -/* On vms we have two kinds of functions: - - - stack frame (PROC_STACK) - these are 'normal' functions with local vars and which are - calling other functions - - register frame (PROC_REGISTER) - keeps all data in registers, needs no stack - - We must pass this to the assembler so it can generate the - proper pdsc (procedure descriptor) - This is done with the '.pdesc' command. - - On not-vms, we don't really differentiate between the two, as we can - simply allocate stack without saving registers. */ - -void -alpha_expand_prologue (void) -{ - /* Registers to save. */ - unsigned long imask = 0; - unsigned long fmask = 0; - /* Stack space needed for pushing registers clobbered by us. */ - HOST_WIDE_INT sa_size; - /* Complete stack size needed. */ - HOST_WIDE_INT frame_size; - /* Offset from base reg to register save area. */ - HOST_WIDE_INT reg_offset; - rtx sa_reg; - int i; - - sa_size = alpha_sa_size (); - - frame_size = get_frame_size (); - if (TARGET_ABI_OPEN_VMS) - frame_size = ALPHA_ROUND (sa_size - + (alpha_procedure_type == PT_STACK ? 8 : 0) - + frame_size - + current_function_pretend_args_size); - else if (TARGET_ABI_UNICOSMK) - /* We have to allocate space for the DSIB if we generate a frame. */ - frame_size = ALPHA_ROUND (sa_size - + (alpha_procedure_type == PT_STACK ? 48 : 0)) - + ALPHA_ROUND (frame_size - + current_function_outgoing_args_size); - else - frame_size = (ALPHA_ROUND (current_function_outgoing_args_size) - + sa_size - + ALPHA_ROUND (frame_size - + current_function_pretend_args_size)); - - if (TARGET_ABI_OPEN_VMS) - reg_offset = 8; - else - reg_offset = ALPHA_ROUND (current_function_outgoing_args_size); - - alpha_sa_mask (&imask, &fmask); - - /* Emit an insn to reload GP, if needed. */ - if (TARGET_ABI_OSF) - { - alpha_function_needs_gp = alpha_does_function_need_gp (); - if (alpha_function_needs_gp) - emit_insn (gen_prologue_ldgp ()); - } - - /* TARGET_PROFILING_NEEDS_GP actually implies that we need to insert - the call to mcount ourselves, rather than having the linker do it - magically in response to -pg. Since _mcount has special linkage, - don't represent the call as a call. */ - if (TARGET_PROFILING_NEEDS_GP && current_function_profile) - emit_insn (gen_prologue_mcount ()); - - if (TARGET_ABI_UNICOSMK) - unicosmk_gen_dsib (&imask); - - /* Adjust the stack by the frame size. If the frame size is > 4096 - bytes, we need to be sure we probe somewhere in the first and last - 4096 bytes (we can probably get away without the latter test) and - every 8192 bytes in between. If the frame size is > 32768, we - do this in a loop. Otherwise, we generate the explicit probe - instructions. - - Note that we are only allowed to adjust sp once in the prologue. */ - - if (frame_size <= 32768) - { - if (frame_size > 4096) - { - int probed = 4096; - - do - emit_insn (gen_probe_stack (GEN_INT (TARGET_ABI_UNICOSMK - ? -probed + 64 - : -probed))); - while ((probed += 8192) < frame_size); - - /* We only have to do this probe if we aren't saving registers. */ - if (sa_size == 0 && probed + 4096 < frame_size) - emit_insn (gen_probe_stack (GEN_INT (-frame_size))); - } - - if (frame_size != 0) - FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx, - GEN_INT (TARGET_ABI_UNICOSMK - ? -frame_size + 64 - : -frame_size)))); - } - else - { - /* Here we generate code to set R22 to SP + 4096 and set R23 to the - number of 8192 byte blocks to probe. We then probe each block - in the loop and then set SP to the proper location. If the - amount remaining is > 4096, we have to do one more probe if we - are not saving any registers. */ - - HOST_WIDE_INT blocks = (frame_size + 4096) / 8192; - HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192; - rtx ptr = gen_rtx_REG (DImode, 22); - rtx count = gen_rtx_REG (DImode, 23); - rtx seq; - - emit_move_insn (count, GEN_INT (blocks)); - emit_insn (gen_adddi3 (ptr, stack_pointer_rtx, - GEN_INT (TARGET_ABI_UNICOSMK ? 4096 - 64 : 4096))); - - /* Because of the difficulty in emitting a new basic block this - late in the compilation, generate the loop as a single insn. */ - emit_insn (gen_prologue_stack_probe_loop (count, ptr)); - - if (leftover > 4096 && sa_size == 0) - { - rtx last = gen_rtx_MEM (DImode, plus_constant (ptr, -leftover)); - MEM_VOLATILE_P (last) = 1; - emit_move_insn (last, const0_rtx); - } - - if (TARGET_ABI_WINDOWS_NT) - { - /* For NT stack unwind (done by 'reverse execution'), it's - not OK to take the result of a loop, even though the value - is already in ptr, so we reload it via a single operation - and subtract it to sp. - - Yes, that's correct -- we have to reload the whole constant - into a temporary via ldah+lda then subtract from sp. */ - - HOST_WIDE_INT lo, hi; - lo = ((frame_size & 0xffff) ^ 0x8000) - 0x8000; - hi = frame_size - lo; - - emit_move_insn (ptr, GEN_INT (hi)); - emit_insn (gen_adddi3 (ptr, ptr, GEN_INT (lo))); - seq = emit_insn (gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx, - ptr)); - } - else - { - seq = emit_insn (gen_adddi3 (stack_pointer_rtx, ptr, - GEN_INT (-leftover))); - } - - /* This alternative is special, because the DWARF code cannot - possibly intuit through the loop above. So we invent this - note it looks at instead. */ - RTX_FRAME_RELATED_P (seq) = 1; - REG_NOTES (seq) - = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, - gen_rtx_SET (VOIDmode, stack_pointer_rtx, - gen_rtx_PLUS (Pmode, stack_pointer_rtx, - GEN_INT (TARGET_ABI_UNICOSMK - ? -frame_size + 64 - : -frame_size))), - REG_NOTES (seq)); - } - - if (!TARGET_ABI_UNICOSMK) - { - HOST_WIDE_INT sa_bias = 0; - - /* Cope with very large offsets to the register save area. */ - sa_reg = stack_pointer_rtx; - if (reg_offset + sa_size > 0x8000) - { - int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000; - rtx sa_bias_rtx; - - if (low + sa_size <= 0x8000) - sa_bias = reg_offset - low, reg_offset = low; - else - sa_bias = reg_offset, reg_offset = 0; - - sa_reg = gen_rtx_REG (DImode, 24); - sa_bias_rtx = GEN_INT (sa_bias); - - if (add_operand (sa_bias_rtx, DImode)) - emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx, sa_bias_rtx)); - else - { - emit_move_insn (sa_reg, sa_bias_rtx); - emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx, sa_reg)); - } - } - - /* Save regs in stack order. Beginning with VMS PV. */ - if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK) - emit_frame_store (REG_PV, stack_pointer_rtx, 0, 0); - - /* Save register RA next. */ - if (imask & (1UL << REG_RA)) - { - emit_frame_store (REG_RA, sa_reg, sa_bias, reg_offset); - imask &= ~(1UL << REG_RA); - reg_offset += 8; - } - - /* Now save any other registers required to be saved. */ - for (i = 0; i < 31; i++) - if (imask & (1UL << i)) - { - emit_frame_store (i, sa_reg, sa_bias, reg_offset); - reg_offset += 8; - } - - for (i = 0; i < 31; i++) - if (fmask & (1UL << i)) - { - emit_frame_store (i+32, sa_reg, sa_bias, reg_offset); - reg_offset += 8; - } - } - else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK) - { - /* The standard frame on the T3E includes space for saving registers. - We just have to use it. We don't have to save the return address and - the old frame pointer here - they are saved in the DSIB. */ - - reg_offset = -56; - for (i = 9; i < 15; i++) - if (imask & (1UL << i)) - { - emit_frame_store (i, hard_frame_pointer_rtx, 0, reg_offset); - reg_offset -= 8; - } - for (i = 2; i < 10; i++) - if (fmask & (1UL << i)) - { - emit_frame_store (i+32, hard_frame_pointer_rtx, 0, reg_offset); - reg_offset -= 8; - } - } - - if (TARGET_ABI_OPEN_VMS) - { - if (alpha_procedure_type == PT_REGISTER) - /* Register frame procedures save the fp. - ?? Ought to have a dwarf2 save for this. */ - emit_move_insn (gen_rtx_REG (DImode, vms_save_fp_regno), - hard_frame_pointer_rtx); - - if (alpha_procedure_type != PT_NULL && vms_base_regno != REG_PV) - emit_insn (gen_force_movdi (gen_rtx_REG (DImode, vms_base_regno), - gen_rtx_REG (DImode, REG_PV))); - - if (alpha_procedure_type != PT_NULL - && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM) - FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx)); - - /* If we have to allocate space for outgoing args, do it now. */ - if (current_function_outgoing_args_size != 0) - { - rtx seq - = emit_move_insn (stack_pointer_rtx, - plus_constant - (hard_frame_pointer_rtx, - - (ALPHA_ROUND - (current_function_outgoing_args_size)))); - - /* Only set FRAME_RELATED_P on the stack adjustment we just emitted - if ! frame_pointer_needed. Setting the bit will change the CFA - computation rule to use sp again, which would be wrong if we had - frame_pointer_needed, as this means sp might move unpredictably - later on. - - Also, note that - frame_pointer_needed - => vms_unwind_regno == HARD_FRAME_POINTER_REGNUM - and - current_function_outgoing_args_size != 0 - => alpha_procedure_type != PT_NULL, - - so when we are not setting the bit here, we are guaranteed to - have emitted an FRP frame pointer update just before. */ - RTX_FRAME_RELATED_P (seq) = ! frame_pointer_needed; - } - } - else if (!TARGET_ABI_UNICOSMK) - { - /* If we need a frame pointer, set it from the stack pointer. */ - if (frame_pointer_needed) - { - if (TARGET_CAN_FAULT_IN_PROLOGUE) - FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx)); - else - /* This must always be the last instruction in the - prologue, thus we emit a special move + clobber. */ - FRP (emit_insn (gen_init_fp (hard_frame_pointer_rtx, - stack_pointer_rtx, sa_reg))); - } - } - - /* The ABIs for VMS and OSF/1 say that while we can schedule insns into - the prologue, for exception handling reasons, we cannot do this for - any insn that might fault. We could prevent this for mems with a - (clobber:BLK (scratch)), but this doesn't work for fp insns. So we - have to prevent all such scheduling with a blockage. - - Linux, on the other hand, never bothered to implement OSF/1's - exception handling, and so doesn't care about such things. Anyone - planning to use dwarf2 frame-unwind info can also omit the blockage. */ - - if (! TARGET_CAN_FAULT_IN_PROLOGUE) - emit_insn (gen_blockage ()); -} - -/* Output the textual info surrounding the prologue. */ - -void -alpha_start_function (FILE *file, const char *fnname, - tree decl ATTRIBUTE_UNUSED) -{ - unsigned long imask = 0; - unsigned long fmask = 0; - /* Stack space needed for pushing registers clobbered by us. */ - HOST_WIDE_INT sa_size; - /* Complete stack size needed. */ - unsigned HOST_WIDE_INT frame_size; - /* Offset from base reg to register save area. */ - HOST_WIDE_INT reg_offset; - char *entry_label = (char *) alloca (strlen (fnname) + 6); - int i; - - /* Don't emit an extern directive for functions defined in the same file. */ - if (TARGET_ABI_UNICOSMK) - { - tree name_tree; - name_tree = get_identifier (fnname); - TREE_ASM_WRITTEN (name_tree) = 1; - } - - alpha_fnname = fnname; - sa_size = alpha_sa_size (); - - frame_size = get_frame_size (); - if (TARGET_ABI_OPEN_VMS) - frame_size = ALPHA_ROUND (sa_size - + (alpha_procedure_type == PT_STACK ? 8 : 0) - + frame_size - + current_function_pretend_args_size); - else if (TARGET_ABI_UNICOSMK) - frame_size = ALPHA_ROUND (sa_size - + (alpha_procedure_type == PT_STACK ? 48 : 0)) - + ALPHA_ROUND (frame_size - + current_function_outgoing_args_size); - else - frame_size = (ALPHA_ROUND (current_function_outgoing_args_size) - + sa_size - + ALPHA_ROUND (frame_size - + current_function_pretend_args_size)); - - if (TARGET_ABI_OPEN_VMS) - reg_offset = 8; - else - reg_offset = ALPHA_ROUND (current_function_outgoing_args_size); - - alpha_sa_mask (&imask, &fmask); - - /* Ecoff can handle multiple .file directives, so put out file and lineno. - We have to do that before the .ent directive as we cannot switch - files within procedures with native ecoff because line numbers are - linked to procedure descriptors. - Outputting the lineno helps debugging of one line functions as they - would otherwise get no line number at all. Please note that we would - like to put out last_linenum from final.c, but it is not accessible. */ - - if (write_symbols == SDB_DEBUG) - { -#ifdef ASM_OUTPUT_SOURCE_FILENAME - ASM_OUTPUT_SOURCE_FILENAME (file, - DECL_SOURCE_FILE (current_function_decl)); -#endif -#ifdef ASM_OUTPUT_SOURCE_LINE - if (debug_info_level != DINFO_LEVEL_TERSE) - ASM_OUTPUT_SOURCE_LINE (file, - DECL_SOURCE_LINE (current_function_decl), 0); -#endif - } - - /* Issue function start and label. */ - if (TARGET_ABI_OPEN_VMS - || (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive)) - { - fputs ("\t.ent ", file); - assemble_name (file, fnname); - putc ('\n', file); - - /* If the function needs GP, we'll write the "..ng" label there. - Otherwise, do it here. */ - if (TARGET_ABI_OSF - && ! alpha_function_needs_gp - && ! current_function_is_thunk) - { - putc ('$', file); - assemble_name (file, fnname); - fputs ("..ng:\n", file); - } - } - - strcpy (entry_label, fnname); - if (TARGET_ABI_OPEN_VMS) - strcat (entry_label, "..en"); - - /* For public functions, the label must be globalized by appending an - additional colon. */ - if (TARGET_ABI_UNICOSMK && TREE_PUBLIC (decl)) - strcat (entry_label, ":"); - - ASM_OUTPUT_LABEL (file, entry_label); - inside_function = TRUE; - - if (TARGET_ABI_OPEN_VMS) - fprintf (file, "\t.base $%d\n", vms_base_regno); - - if (!TARGET_ABI_OPEN_VMS && !TARGET_ABI_UNICOSMK && TARGET_IEEE_CONFORMANT - && !flag_inhibit_size_directive) - { - /* Set flags in procedure descriptor to request IEEE-conformant - math-library routines. The value we set it to is PDSC_EXC_IEEE - (/usr/include/pdsc.h). */ - fputs ("\t.eflag 48\n", file); - } - - /* Set up offsets to alpha virtual arg/local debugging pointer. */ - alpha_auto_offset = -frame_size + current_function_pretend_args_size; - alpha_arg_offset = -frame_size + 48; - - /* Describe our frame. If the frame size is larger than an integer, - print it as zero to avoid an assembler error. We won't be - properly describing such a frame, but that's the best we can do. */ - if (TARGET_ABI_UNICOSMK) - ; - else if (TARGET_ABI_OPEN_VMS) - fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26," - HOST_WIDE_INT_PRINT_DEC "\n", - vms_unwind_regno, - frame_size >= (1UL << 31) ? 0 : frame_size, - reg_offset); - else if (!flag_inhibit_size_directive) - fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,%d\n", - (frame_pointer_needed - ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM), - frame_size >= (1UL << 31) ? 0 : frame_size, - current_function_pretend_args_size); - - /* Describe which registers were spilled. */ - if (TARGET_ABI_UNICOSMK) - ; - else if (TARGET_ABI_OPEN_VMS) - { - if (imask) - /* ??? Does VMS care if mask contains ra? The old code didn't - set it, so I don't here. */ - fprintf (file, "\t.mask 0x%lx,0\n", imask & ~(1UL << REG_RA)); - if (fmask) - fprintf (file, "\t.fmask 0x%lx,0\n", fmask); - if (alpha_procedure_type == PT_REGISTER) - fprintf (file, "\t.fp_save $%d\n", vms_save_fp_regno); - } - else if (!flag_inhibit_size_directive) - { - if (imask) - { - fprintf (file, "\t.mask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", imask, - frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size); - - for (i = 0; i < 32; ++i) - if (imask & (1UL << i)) - reg_offset += 8; - } - - if (fmask) - fprintf (file, "\t.fmask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", fmask, - frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size); - } - -#if TARGET_ABI_OPEN_VMS - /* Ifdef'ed cause link_section are only available then. */ - readonly_data_section (); - fprintf (file, "\t.align 3\n"); - assemble_name (file, fnname); fputs ("..na:\n", file); - fputs ("\t.ascii \"", file); - assemble_name (file, fnname); - fputs ("\\0\"\n", file); - alpha_need_linkage (fnname, 1); - text_section (); -#endif -} - -/* Emit the .prologue note at the scheduled end of the prologue. */ - -static void -alpha_output_function_end_prologue (FILE *file) -{ - if (TARGET_ABI_UNICOSMK) - ; - else if (TARGET_ABI_OPEN_VMS) - fputs ("\t.prologue\n", file); - else if (TARGET_ABI_WINDOWS_NT) - fputs ("\t.prologue 0\n", file); - else if (!flag_inhibit_size_directive) - fprintf (file, "\t.prologue %d\n", - alpha_function_needs_gp || current_function_is_thunk); -} - -/* Write function epilogue. */ - -/* ??? At some point we will want to support full unwind, and so will - need to mark the epilogue as well. At the moment, we just confuse - dwarf2out. */ -#undef FRP -#define FRP(exp) exp - -void -alpha_expand_epilogue (void) -{ - /* Registers to save. */ - unsigned long imask = 0; - unsigned long fmask = 0; - /* Stack space needed for pushing registers clobbered by us. */ - HOST_WIDE_INT sa_size; - /* Complete stack size needed. */ - HOST_WIDE_INT frame_size; - /* Offset from base reg to register save area. */ - HOST_WIDE_INT reg_offset; - int fp_is_frame_pointer, fp_offset; - rtx sa_reg, sa_reg_exp = NULL; - rtx sp_adj1, sp_adj2, mem; - rtx eh_ofs; - int i; - - sa_size = alpha_sa_size (); - - frame_size = get_frame_size (); - if (TARGET_ABI_OPEN_VMS) - frame_size = ALPHA_ROUND (sa_size - + (alpha_procedure_type == PT_STACK ? 8 : 0) - + frame_size - + current_function_pretend_args_size); - else if (TARGET_ABI_UNICOSMK) - frame_size = ALPHA_ROUND (sa_size - + (alpha_procedure_type == PT_STACK ? 48 : 0)) - + ALPHA_ROUND (frame_size - + current_function_outgoing_args_size); - else - frame_size = (ALPHA_ROUND (current_function_outgoing_args_size) - + sa_size - + ALPHA_ROUND (frame_size - + current_function_pretend_args_size)); - - if (TARGET_ABI_OPEN_VMS) - { - if (alpha_procedure_type == PT_STACK) - reg_offset = 8; - else - reg_offset = 0; - } - else - reg_offset = ALPHA_ROUND (current_function_outgoing_args_size); - - alpha_sa_mask (&imask, &fmask); - - fp_is_frame_pointer - = ((TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK) - || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed)); - fp_offset = 0; - sa_reg = stack_pointer_rtx; - - if (current_function_calls_eh_return) - eh_ofs = EH_RETURN_STACKADJ_RTX; - else - eh_ofs = NULL_RTX; - - if (!TARGET_ABI_UNICOSMK && sa_size) - { - /* If we have a frame pointer, restore SP from it. */ - if ((TARGET_ABI_OPEN_VMS - && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM) - || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed)) - FRP (emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx)); - - /* Cope with very large offsets to the register save area. */ - if (reg_offset + sa_size > 0x8000) - { - int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000; - HOST_WIDE_INT bias; - - if (low + sa_size <= 0x8000) - bias = reg_offset - low, reg_offset = low; - else - bias = reg_offset, reg_offset = 0; - - sa_reg = gen_rtx_REG (DImode, 22); - sa_reg_exp = plus_constant (stack_pointer_rtx, bias); - - FRP (emit_move_insn (sa_reg, sa_reg_exp)); - } - - /* Restore registers in order, excepting a true frame pointer. */ - - mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset)); - if (! eh_ofs) - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem)); - - reg_offset += 8; - imask &= ~(1UL << REG_RA); - - for (i = 0; i < 31; ++i) - if (imask & (1UL << i)) - { - if (i == HARD_FRAME_POINTER_REGNUM && fp_is_frame_pointer) - fp_offset = reg_offset; - else - { - mem = gen_rtx_MEM (DImode, plus_constant(sa_reg, reg_offset)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem)); - } - reg_offset += 8; - } - - for (i = 0; i < 31; ++i) - if (fmask & (1UL << i)) - { - mem = gen_rtx_MEM (DFmode, plus_constant(sa_reg, reg_offset)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem)); - reg_offset += 8; - } - } - else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK) - { - /* Restore callee-saved general-purpose registers. */ - - reg_offset = -56; - - for (i = 9; i < 15; i++) - if (imask & (1UL << i)) - { - mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx, - reg_offset)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem)); - reg_offset -= 8; - } - - for (i = 2; i < 10; i++) - if (fmask & (1UL << i)) - { - mem = gen_rtx_MEM (DFmode, plus_constant(hard_frame_pointer_rtx, - reg_offset)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem)); - reg_offset -= 8; - } - - /* Restore the return address from the DSIB. */ - - mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx, -8)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem)); - } - - if (frame_size || eh_ofs) - { - sp_adj1 = stack_pointer_rtx; - - if (eh_ofs) - { - sp_adj1 = gen_rtx_REG (DImode, 23); - emit_move_insn (sp_adj1, - gen_rtx_PLUS (Pmode, stack_pointer_rtx, eh_ofs)); - } - - /* If the stack size is large, begin computation into a temporary - register so as not to interfere with a potential fp restore, - which must be consecutive with an SP restore. */ - if (frame_size < 32768 - && ! (TARGET_ABI_UNICOSMK && current_function_calls_alloca)) - sp_adj2 = GEN_INT (frame_size); - else if (TARGET_ABI_UNICOSMK) - { - sp_adj1 = gen_rtx_REG (DImode, 23); - FRP (emit_move_insn (sp_adj1, hard_frame_pointer_rtx)); - sp_adj2 = const0_rtx; - } - else if (frame_size < 0x40007fffL) - { - int low = ((frame_size & 0xffff) ^ 0x8000) - 0x8000; - - sp_adj2 = plus_constant (sp_adj1, frame_size - low); - if (sa_reg_exp && rtx_equal_p (sa_reg_exp, sp_adj2)) - sp_adj1 = sa_reg; - else - { - sp_adj1 = gen_rtx_REG (DImode, 23); - FRP (emit_move_insn (sp_adj1, sp_adj2)); - } - sp_adj2 = GEN_INT (low); - } - else - { - rtx tmp = gen_rtx_REG (DImode, 23); - FRP (sp_adj2 = alpha_emit_set_const (tmp, DImode, frame_size, 3)); - if (!sp_adj2) - { - /* We can't drop new things to memory this late, afaik, - so build it up by pieces. */ - FRP (sp_adj2 = alpha_emit_set_long_const (tmp, frame_size, - -(frame_size < 0))); - if (!sp_adj2) - abort (); - } - } - - /* From now on, things must be in order. So emit blockages. */ - - /* Restore the frame pointer. */ - if (TARGET_ABI_UNICOSMK) - { - emit_insn (gen_blockage ()); - mem = gen_rtx_MEM (DImode, - plus_constant (hard_frame_pointer_rtx, -16)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (hard_frame_pointer_rtx, mem)); - } - else if (fp_is_frame_pointer) - { - emit_insn (gen_blockage ()); - mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, fp_offset)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (hard_frame_pointer_rtx, mem)); - } - else if (TARGET_ABI_OPEN_VMS) - { - emit_insn (gen_blockage ()); - FRP (emit_move_insn (hard_frame_pointer_rtx, - gen_rtx_REG (DImode, vms_save_fp_regno))); - } - - /* Restore the stack pointer. */ - emit_insn (gen_blockage ()); - if (sp_adj2 == const0_rtx) - FRP (emit_move_insn (stack_pointer_rtx, sp_adj1)); - else - FRP (emit_move_insn (stack_pointer_rtx, - gen_rtx_PLUS (DImode, sp_adj1, sp_adj2))); - } - else - { - if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_REGISTER) - { - emit_insn (gen_blockage ()); - FRP (emit_move_insn (hard_frame_pointer_rtx, - gen_rtx_REG (DImode, vms_save_fp_regno))); - } - else if (TARGET_ABI_UNICOSMK && alpha_procedure_type != PT_STACK) - { - /* Decrement the frame pointer if the function does not have a - frame. */ - - emit_insn (gen_blockage ()); - FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx, - hard_frame_pointer_rtx, GEN_INT (-1)))); - } - } -} - -/* Output the rest of the textual info surrounding the epilogue. */ - -void -alpha_end_function (FILE *file, const char *fnname, tree decl ATTRIBUTE_UNUSED) -{ - /* End the function. */ - if (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive) - { - fputs ("\t.end ", file); - assemble_name (file, fnname); - putc ('\n', file); - } - inside_function = FALSE; - -#if TARGET_ABI_OPEN_VMS - alpha_write_linkage (file, fnname, decl); -#endif - - /* Output jump tables and the static subroutine information block. */ - if (TARGET_ABI_UNICOSMK) - { - unicosmk_output_ssib (file, fnname); - unicosmk_output_deferred_case_vectors (file); - } -} - -#if TARGET_ABI_OSF -/* Emit a tail call to FUNCTION after adjusting THIS by DELTA. - - In order to avoid the hordes of differences between generated code - with and without TARGET_EXPLICIT_RELOCS, and to avoid duplicating - lots of code loading up large constants, generate rtl and emit it - instead of going straight to text. - - Not sure why this idea hasn't been explored before... */ - -static void -alpha_output_mi_thunk_osf (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, - HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, - tree function) -{ - HOST_WIDE_INT hi, lo; - rtx this, insn, funexp; - - /* We always require a valid GP. */ - emit_insn (gen_prologue_ldgp ()); - emit_note (NOTE_INSN_PROLOGUE_END); - - /* Find the "this" pointer. If the function returns a structure, - the structure return pointer is in $16. */ - if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) - this = gen_rtx_REG (Pmode, 17); - else - this = gen_rtx_REG (Pmode, 16); - - /* Add DELTA. When possible we use ldah+lda. Otherwise load the - entire constant for the add. */ - lo = ((delta & 0xffff) ^ 0x8000) - 0x8000; - hi = (((delta - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000; - if (hi + lo == delta) - { - if (hi) - emit_insn (gen_adddi3 (this, this, GEN_INT (hi))); - if (lo) - emit_insn (gen_adddi3 (this, this, GEN_INT (lo))); - } - else - { - rtx tmp = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 0), - delta, -(delta < 0)); - emit_insn (gen_adddi3 (this, this, tmp)); - } - - /* Add a delta stored in the vtable at VCALL_OFFSET. */ - if (vcall_offset) - { - rtx tmp, tmp2; - - tmp = gen_rtx_REG (Pmode, 0); - emit_move_insn (tmp, gen_rtx_MEM (Pmode, this)); - - lo = ((vcall_offset & 0xffff) ^ 0x8000) - 0x8000; - hi = (((vcall_offset - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000; - if (hi + lo == vcall_offset) - { - if (hi) - emit_insn (gen_adddi3 (tmp, tmp, GEN_INT (hi))); - } - else - { - tmp2 = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 1), - vcall_offset, -(vcall_offset < 0)); - emit_insn (gen_adddi3 (tmp, tmp, tmp2)); - lo = 0; - } - if (lo) - tmp2 = gen_rtx_PLUS (Pmode, tmp, GEN_INT (lo)); - else - tmp2 = tmp; - emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp2)); - - emit_insn (gen_adddi3 (this, this, tmp)); - } - - /* Generate a tail call to the target function. */ - if (! TREE_USED (function)) - { - assemble_external (function); - TREE_USED (function) = 1; - } - funexp = XEXP (DECL_RTL (function), 0); - funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); - insn = emit_call_insn (gen_sibcall (funexp, const0_rtx)); - SIBLING_CALL_P (insn) = 1; - - /* Run just enough of rest_of_compilation to get the insns emitted. - There's not really enough bulk here to make other passes such as - instruction scheduling worth while. Note that use_thunk calls - assemble_start_function and assemble_end_function. */ - insn = get_insns (); - insn_locators_initialize (); - shorten_branches (insn); - final_start_function (insn, file, 1); - final (insn, file, 1, 0); - final_end_function (); -} -#endif /* TARGET_ABI_OSF */ - -/* Debugging support. */ - -#include "gstab.h" - -/* Count the number of sdb related labels are generated (to find block - start and end boundaries). */ - -int sdb_label_count = 0; - -/* Next label # for each statement. */ - -static int sym_lineno = 0; - -/* Count the number of .file directives, so that .loc is up to date. */ - -static int num_source_filenames = 0; - -/* Name of the file containing the current function. */ - -static const char *current_function_file = ""; - -/* Offsets to alpha virtual arg/local debugging pointers. */ - -long alpha_arg_offset; -long alpha_auto_offset; - -/* Emit a new filename to a stream. */ - -void -alpha_output_filename (FILE *stream, const char *name) -{ - static int first_time = TRUE; - char ltext_label_name[100]; - - if (first_time) - { - first_time = FALSE; - ++num_source_filenames; - current_function_file = name; - fprintf (stream, "\t.file\t%d ", num_source_filenames); - output_quoted_string (stream, name); - fprintf (stream, "\n"); - if (!TARGET_GAS && write_symbols == DBX_DEBUG) - fprintf (stream, "\t#@stabs\n"); - } - - else if (write_symbols == DBX_DEBUG) - { - ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0); - fprintf (stream, "%s", ASM_STABS_OP); - output_quoted_string (stream, name); - fprintf (stream, ",%d,0,0,%s\n", N_SOL, <ext_label_name[1]); - } - - else if (name != current_function_file - && strcmp (name, current_function_file) != 0) - { - if (inside_function && ! TARGET_GAS) - fprintf (stream, "\t#.file\t%d ", num_source_filenames); - else - { - ++num_source_filenames; - current_function_file = name; - fprintf (stream, "\t.file\t%d ", num_source_filenames); - } - - output_quoted_string (stream, name); - fprintf (stream, "\n"); - } -} - -/* Emit a linenumber to a stream. */ - -void -alpha_output_lineno (FILE *stream, int line) -{ - if (write_symbols == DBX_DEBUG) - { - /* mips-tfile doesn't understand .stabd directives. */ - ++sym_lineno; - fprintf (stream, "$LM%d:\n%s%d,0,%d,$LM%d\n", - sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno); - } - else - fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line); -} - -/* Structure to show the current status of registers and memory. */ - -struct shadow_summary -{ - struct { - unsigned int i : 31; /* Mask of int regs */ - unsigned int fp : 31; /* Mask of fp regs */ - unsigned int mem : 1; /* mem == imem | fpmem */ - } used, defd; -}; - -/* Summary the effects of expression X on the machine. Update SUM, a pointer - to the summary structure. SET is nonzero if the insn is setting the - object, otherwise zero. */ - -static void -summarize_insn (rtx x, struct shadow_summary *sum, int set) -{ - const char *format_ptr; - int i, j; - - if (x == 0) - return; - - switch (GET_CODE (x)) - { - /* ??? Note that this case would be incorrect if the Alpha had a - ZERO_EXTRACT in SET_DEST. */ - case SET: - summarize_insn (SET_SRC (x), sum, 0); - summarize_insn (SET_DEST (x), sum, 1); - break; - - case CLOBBER: - summarize_insn (XEXP (x, 0), sum, 1); - break; - - case USE: - summarize_insn (XEXP (x, 0), sum, 0); - break; - - case ASM_OPERANDS: - for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--) - summarize_insn (ASM_OPERANDS_INPUT (x, i), sum, 0); - break; - - case PARALLEL: - for (i = XVECLEN (x, 0) - 1; i >= 0; i--) - summarize_insn (XVECEXP (x, 0, i), sum, 0); - break; - - case SUBREG: - summarize_insn (SUBREG_REG (x), sum, 0); - break; - - case REG: - { - int regno = REGNO (x); - unsigned long mask = ((unsigned long) 1) << (regno % 32); - - if (regno == 31 || regno == 63) - break; - - if (set) - { - if (regno < 32) - sum->defd.i |= mask; - else - sum->defd.fp |= mask; - } - else - { - if (regno < 32) - sum->used.i |= mask; - else - sum->used.fp |= mask; - } - } - break; - - case MEM: - if (set) - sum->defd.mem = 1; - else - sum->used.mem = 1; - - /* Find the regs used in memory address computation: */ - summarize_insn (XEXP (x, 0), sum, 0); - break; - - case CONST_INT: case CONST_DOUBLE: - case SYMBOL_REF: case LABEL_REF: case CONST: - case SCRATCH: case ASM_INPUT: - break; - - /* Handle common unary and binary ops for efficiency. */ - case COMPARE: case PLUS: case MINUS: case MULT: case DIV: - case MOD: case UDIV: case UMOD: case AND: case IOR: - case XOR: case ASHIFT: case ROTATE: case ASHIFTRT: case LSHIFTRT: - case ROTATERT: case SMIN: case SMAX: case UMIN: case UMAX: - case NE: case EQ: case GE: case GT: case LE: - case LT: case GEU: case GTU: case LEU: case LTU: - summarize_insn (XEXP (x, 0), sum, 0); - summarize_insn (XEXP (x, 1), sum, 0); - break; - - case NEG: case NOT: case SIGN_EXTEND: case ZERO_EXTEND: - case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: case FLOAT: - case FIX: case UNSIGNED_FLOAT: case UNSIGNED_FIX: case ABS: - case SQRT: case FFS: - summarize_insn (XEXP (x, 0), sum, 0); - break; - - default: - format_ptr = GET_RTX_FORMAT (GET_CODE (x)); - for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) - switch (format_ptr[i]) - { - case 'e': - summarize_insn (XEXP (x, i), sum, 0); - break; - - case 'E': - for (j = XVECLEN (x, i) - 1; j >= 0; j--) - summarize_insn (XVECEXP (x, i, j), sum, 0); - break; - - case 'i': - break; - - default: - abort (); - } - } -} - -/* Ensure a sufficient number of `trapb' insns are in the code when - the user requests code with a trap precision of functions or - instructions. - - In naive mode, when the user requests a trap-precision of - "instruction", a trapb is needed after every instruction that may - generate a trap. This ensures that the code is resumption safe but - it is also slow. - - When optimizations are turned on, we delay issuing a trapb as long - as possible. In this context, a trap shadow is the sequence of - instructions that starts with a (potentially) trap generating - instruction and extends to the next trapb or call_pal instruction - (but GCC never generates call_pal by itself). We can delay (and - therefore sometimes omit) a trapb subject to the following - conditions: - - (a) On entry to the trap shadow, if any Alpha register or memory - location contains a value that is used as an operand value by some - instruction in the trap shadow (live on entry), then no instruction - in the trap shadow may modify the register or memory location. - - (b) Within the trap shadow, the computation of the base register - for a memory load or store instruction may not involve using the - result of an instruction that might generate an UNPREDICTABLE - result. - - (c) Within the trap shadow, no register may be used more than once - as a destination register. (This is to make life easier for the - trap-handler.) - - (d) The trap shadow may not include any branch instructions. */ - -static void -alpha_handle_trap_shadows (void) -{ - struct shadow_summary shadow; - int trap_pending, exception_nesting; - rtx i, n; - - trap_pending = 0; - exception_nesting = 0; - shadow.used.i = 0; - shadow.used.fp = 0; - shadow.used.mem = 0; - shadow.defd = shadow.used; - - for (i = get_insns (); i ; i = NEXT_INSN (i)) - { - if (GET_CODE (i) == NOTE) - { - switch (NOTE_LINE_NUMBER (i)) - { - case NOTE_INSN_EH_REGION_BEG: - exception_nesting++; - if (trap_pending) - goto close_shadow; - break; - - case NOTE_INSN_EH_REGION_END: - exception_nesting--; - if (trap_pending) - goto close_shadow; - break; - - case NOTE_INSN_EPILOGUE_BEG: - if (trap_pending && alpha_tp >= ALPHA_TP_FUNC) - goto close_shadow; - break; - } - } - else if (trap_pending) - { - if (alpha_tp == ALPHA_TP_FUNC) - { - if (GET_CODE (i) == JUMP_INSN - && GET_CODE (PATTERN (i)) == RETURN) - goto close_shadow; - } - else if (alpha_tp == ALPHA_TP_INSN) - { - if (optimize > 0) - { - struct shadow_summary sum; - - sum.used.i = 0; - sum.used.fp = 0; - sum.used.mem = 0; - sum.defd = sum.used; - - switch (GET_CODE (i)) - { - case INSN: - /* Annoyingly, get_attr_trap will abort on these. */ - if (GET_CODE (PATTERN (i)) == USE - || GET_CODE (PATTERN (i)) == CLOBBER) - break; - - summarize_insn (PATTERN (i), &sum, 0); - - if ((sum.defd.i & shadow.defd.i) - || (sum.defd.fp & shadow.defd.fp)) - { - /* (c) would be violated */ - goto close_shadow; - } - - /* Combine shadow with summary of current insn: */ - shadow.used.i |= sum.used.i; - shadow.used.fp |= sum.used.fp; - shadow.used.mem |= sum.used.mem; - shadow.defd.i |= sum.defd.i; - shadow.defd.fp |= sum.defd.fp; - shadow.defd.mem |= sum.defd.mem; - - if ((sum.defd.i & shadow.used.i) - || (sum.defd.fp & shadow.used.fp) - || (sum.defd.mem & shadow.used.mem)) - { - /* (a) would be violated (also takes care of (b)) */ - if (get_attr_trap (i) == TRAP_YES - && ((sum.defd.i & sum.used.i) - || (sum.defd.fp & sum.used.fp))) - abort (); - - goto close_shadow; - } - break; - - case JUMP_INSN: - case CALL_INSN: - case CODE_LABEL: - goto close_shadow; - - default: - abort (); - } - } - else - { - close_shadow: - n = emit_insn_before (gen_trapb (), i); - PUT_MODE (n, TImode); - PUT_MODE (i, TImode); - trap_pending = 0; - shadow.used.i = 0; - shadow.used.fp = 0; - shadow.used.mem = 0; - shadow.defd = shadow.used; - } - } - } - - if ((exception_nesting > 0 || alpha_tp >= ALPHA_TP_FUNC) - && GET_CODE (i) == INSN - && GET_CODE (PATTERN (i)) != USE - && GET_CODE (PATTERN (i)) != CLOBBER - && get_attr_trap (i) == TRAP_YES) - { - if (optimize && !trap_pending) - summarize_insn (PATTERN (i), &shadow, 0); - trap_pending = 1; - } - } -} - -/* Alpha can only issue instruction groups simultaneously if they are - suitably aligned. This is very processor-specific. */ - -enum alphaev4_pipe { - EV4_STOP = 0, - EV4_IB0 = 1, - EV4_IB1 = 2, - EV4_IBX = 4 -}; - -enum alphaev5_pipe { - EV5_STOP = 0, - EV5_NONE = 1, - EV5_E01 = 2, - EV5_E0 = 4, - EV5_E1 = 8, - EV5_FAM = 16, - EV5_FA = 32, - EV5_FM = 64 -}; - -static enum alphaev4_pipe -alphaev4_insn_pipe (rtx insn) -{ - if (recog_memoized (insn) < 0) - return EV4_STOP; - if (get_attr_length (insn) != 4) - return EV4_STOP; - - switch (get_attr_type (insn)) - { - case TYPE_ILD: - case TYPE_FLD: - return EV4_IBX; - - case TYPE_LDSYM: - case TYPE_IADD: - case TYPE_ILOG: - case TYPE_ICMOV: - case TYPE_ICMP: - case TYPE_IST: - case TYPE_FST: - case TYPE_SHIFT: - case TYPE_IMUL: - case TYPE_FBR: - return EV4_IB0; - - case TYPE_MISC: - case TYPE_IBR: - case TYPE_JSR: - case TYPE_CALLPAL: - case TYPE_FCPYS: - case TYPE_FCMOV: - case TYPE_FADD: - case TYPE_FDIV: - case TYPE_FMUL: - return EV4_IB1; - - default: - abort (); - } -} - -static enum alphaev5_pipe -alphaev5_insn_pipe (rtx insn) -{ - if (recog_memoized (insn) < 0) - return EV5_STOP; - if (get_attr_length (insn) != 4) - return EV5_STOP; - - switch (get_attr_type (insn)) - { - case TYPE_ILD: - case TYPE_FLD: - case TYPE_LDSYM: - case TYPE_IADD: - case TYPE_ILOG: - case TYPE_ICMOV: - case TYPE_ICMP: - return EV5_E01; - - case TYPE_IST: - case TYPE_FST: - case TYPE_SHIFT: - case TYPE_IMUL: - case TYPE_MISC: - case TYPE_MVI: - return EV5_E0; - - case TYPE_IBR: - case TYPE_JSR: - case TYPE_CALLPAL: - return EV5_E1; - - case TYPE_FCPYS: - return EV5_FAM; - - case TYPE_FBR: - case TYPE_FCMOV: - case TYPE_FADD: - case TYPE_FDIV: - return EV5_FA; - - case TYPE_FMUL: - return EV5_FM; - - default: - abort(); - } -} - -/* IN_USE is a mask of the slots currently filled within the insn group. - The mask bits come from alphaev4_pipe above. If EV4_IBX is set, then - the insn in EV4_IB0 can be swapped by the hardware into EV4_IB1. - - LEN is, of course, the length of the group in bytes. */ - -static rtx -alphaev4_next_group (rtx insn, int *pin_use, int *plen) -{ - int len, in_use; - - len = in_use = 0; - - if (! INSN_P (insn) - || GET_CODE (PATTERN (insn)) == CLOBBER - || GET_CODE (PATTERN (insn)) == USE) - goto next_and_done; - - while (1) - { - enum alphaev4_pipe pipe; - - pipe = alphaev4_insn_pipe (insn); - switch (pipe) - { - case EV4_STOP: - /* Force complex instructions to start new groups. */ - if (in_use) - goto done; - - /* If this is a completely unrecognized insn, its an asm. - We don't know how long it is, so record length as -1 to - signal a needed realignment. */ - if (recog_memoized (insn) < 0) - len = -1; - else - len = get_attr_length (insn); - goto next_and_done; - - case EV4_IBX: - if (in_use & EV4_IB0) - { - if (in_use & EV4_IB1) - goto done; - in_use |= EV4_IB1; - } - else - in_use |= EV4_IB0 | EV4_IBX; - break; - - case EV4_IB0: - if (in_use & EV4_IB0) - { - if (!(in_use & EV4_IBX) || (in_use & EV4_IB1)) - goto done; - in_use |= EV4_IB1; - } - in_use |= EV4_IB0; - break; - - case EV4_IB1: - if (in_use & EV4_IB1) - goto done; - in_use |= EV4_IB1; - break; - - default: - abort(); - } - len += 4; - - /* Haifa doesn't do well scheduling branches. */ - if (GET_CODE (insn) == JUMP_INSN) - goto next_and_done; - - next: - insn = next_nonnote_insn (insn); - - if (!insn || ! INSN_P (insn)) - goto done; - - /* Let Haifa tell us where it thinks insn group boundaries are. */ - if (GET_MODE (insn) == TImode) - goto done; - - if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE) - goto next; - } - - next_and_done: - insn = next_nonnote_insn (insn); - - done: - *plen = len; - *pin_use = in_use; - return insn; -} - -/* IN_USE is a mask of the slots currently filled within the insn group. - The mask bits come from alphaev5_pipe above. If EV5_E01 is set, then - the insn in EV5_E0 can be swapped by the hardware into EV5_E1. - - LEN is, of course, the length of the group in bytes. */ - -static rtx -alphaev5_next_group (rtx insn, int *pin_use, int *plen) -{ - int len, in_use; - - len = in_use = 0; - - if (! INSN_P (insn) - || GET_CODE (PATTERN (insn)) == CLOBBER - || GET_CODE (PATTERN (insn)) == USE) - goto next_and_done; - - while (1) - { - enum alphaev5_pipe pipe; - - pipe = alphaev5_insn_pipe (insn); - switch (pipe) - { - case EV5_STOP: - /* Force complex instructions to start new groups. */ - if (in_use) - goto done; - - /* If this is a completely unrecognized insn, its an asm. - We don't know how long it is, so record length as -1 to - signal a needed realignment. */ - if (recog_memoized (insn) < 0) - len = -1; - else - len = get_attr_length (insn); - goto next_and_done; - - /* ??? Most of the places below, we would like to abort, as - it would indicate an error either in Haifa, or in the - scheduling description. Unfortunately, Haifa never - schedules the last instruction of the BB, so we don't - have an accurate TI bit to go off. */ - case EV5_E01: - if (in_use & EV5_E0) - { - if (in_use & EV5_E1) - goto done; - in_use |= EV5_E1; - } - else - in_use |= EV5_E0 | EV5_E01; - break; - - case EV5_E0: - if (in_use & EV5_E0) - { - if (!(in_use & EV5_E01) || (in_use & EV5_E1)) - goto done; - in_use |= EV5_E1; - } - in_use |= EV5_E0; - break; - - case EV5_E1: - if (in_use & EV5_E1) - goto done; - in_use |= EV5_E1; - break; - - case EV5_FAM: - if (in_use & EV5_FA) - { - if (in_use & EV5_FM) - goto done; - in_use |= EV5_FM; - } - else - in_use |= EV5_FA | EV5_FAM; - break; - - case EV5_FA: - if (in_use & EV5_FA) - goto done; - in_use |= EV5_FA; - break; - - case EV5_FM: - if (in_use & EV5_FM) - goto done; - in_use |= EV5_FM; - break; - - case EV5_NONE: - break; - - default: - abort(); - } - len += 4; - - /* Haifa doesn't do well scheduling branches. */ - /* ??? If this is predicted not-taken, slotting continues, except - that no more IBR, FBR, or JSR insns may be slotted. */ - if (GET_CODE (insn) == JUMP_INSN) - goto next_and_done; - - next: - insn = next_nonnote_insn (insn); - - if (!insn || ! INSN_P (insn)) - goto done; - - /* Let Haifa tell us where it thinks insn group boundaries are. */ - if (GET_MODE (insn) == TImode) - goto done; - - if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE) - goto next; - } - - next_and_done: - insn = next_nonnote_insn (insn); - - done: - *plen = len; - *pin_use = in_use; - return insn; -} - -static rtx -alphaev4_next_nop (int *pin_use) -{ - int in_use = *pin_use; - rtx nop; - - if (!(in_use & EV4_IB0)) - { - in_use |= EV4_IB0; - nop = gen_nop (); - } - else if ((in_use & (EV4_IBX|EV4_IB1)) == EV4_IBX) - { - in_use |= EV4_IB1; - nop = gen_nop (); - } - else if (TARGET_FP && !(in_use & EV4_IB1)) - { - in_use |= EV4_IB1; - nop = gen_fnop (); - } - else - nop = gen_unop (); - - *pin_use = in_use; - return nop; -} - -static rtx -alphaev5_next_nop (int *pin_use) -{ - int in_use = *pin_use; - rtx nop; - - if (!(in_use & EV5_E1)) - { - in_use |= EV5_E1; - nop = gen_nop (); - } - else if (TARGET_FP && !(in_use & EV5_FA)) - { - in_use |= EV5_FA; - nop = gen_fnop (); - } - else if (TARGET_FP && !(in_use & EV5_FM)) - { - in_use |= EV5_FM; - nop = gen_fnop (); - } - else - nop = gen_unop (); - - *pin_use = in_use; - return nop; -} - -/* The instruction group alignment main loop. */ - -static void -alpha_align_insns (unsigned int max_align, - rtx (*next_group) (rtx, int *, int *), - rtx (*next_nop) (int *)) -{ - /* ALIGN is the known alignment for the insn group. */ - unsigned int align; - /* OFS is the offset of the current insn in the insn group. */ - int ofs; - int prev_in_use, in_use, len, ldgp; - rtx i, next; - - /* Let shorten branches care for assigning alignments to code labels. */ - shorten_branches (get_insns ()); - - if (align_functions < 4) - align = 4; - else if ((unsigned int) align_functions < max_align) - align = align_functions; - else - align = max_align; - - ofs = prev_in_use = 0; - i = get_insns (); - if (GET_CODE (i) == NOTE) - i = next_nonnote_insn (i); - - ldgp = alpha_function_needs_gp ? 8 : 0; - - while (i) - { - next = (*next_group) (i, &in_use, &len); - - /* When we see a label, resync alignment etc. */ - if (GET_CODE (i) == CODE_LABEL) - { - unsigned int new_align = 1 << label_to_alignment (i); - - if (new_align >= align) - { - align = new_align < max_align ? new_align : max_align; - ofs = 0; - } - - else if (ofs & (new_align-1)) - ofs = (ofs | (new_align-1)) + 1; - if (len != 0) - abort(); - } - - /* Handle complex instructions special. */ - else if (in_use == 0) - { - /* Asms will have length < 0. This is a signal that we have - lost alignment knowledge. Assume, however, that the asm - will not mis-align instructions. */ - if (len < 0) - { - ofs = 0; - align = 4; - len = 0; - } - } - - /* If the known alignment is smaller than the recognized insn group, - realign the output. */ - else if ((int) align < len) - { - unsigned int new_log_align = len > 8 ? 4 : 3; - rtx prev, where; - - where = prev = prev_nonnote_insn (i); - if (!where || GET_CODE (where) != CODE_LABEL) - where = i; - - /* Can't realign between a call and its gp reload. */ - if (! (TARGET_EXPLICIT_RELOCS - && prev && GET_CODE (prev) == CALL_INSN)) - { - emit_insn_before (gen_realign (GEN_INT (new_log_align)), where); - align = 1 << new_log_align; - ofs = 0; - } - } - - /* We may not insert padding inside the initial ldgp sequence. */ - else if (ldgp > 0) - ldgp -= len; - - /* If the group won't fit in the same INT16 as the previous, - we need to add padding to keep the group together. Rather - than simply leaving the insn filling to the assembler, we - can make use of the knowledge of what sorts of instructions - were issued in the previous group to make sure that all of - the added nops are really free. */ - else if (ofs + len > (int) align) - { - int nop_count = (align - ofs) / 4; - rtx where; - - /* Insert nops before labels, branches, and calls to truly merge - the execution of the nops with the previous instruction group. */ - where = prev_nonnote_insn (i); - if (where) - { - if (GET_CODE (where) == CODE_LABEL) - { - rtx where2 = prev_nonnote_insn (where); - if (where2 && GET_CODE (where2) == JUMP_INSN) - where = where2; - } - else if (GET_CODE (where) == INSN) - where = i; - } - else - where = i; - - do - emit_insn_before ((*next_nop)(&prev_in_use), where); - while (--nop_count); - ofs = 0; - } - - ofs = (ofs + len) & (align - 1); - prev_in_use = in_use; - i = next; - } -} - -/* Machine dependent reorg pass. */ - -static void -alpha_reorg (void) -{ - if (alpha_tp != ALPHA_TP_PROG || flag_exceptions) - alpha_handle_trap_shadows (); - - /* Due to the number of extra trapb insns, don't bother fixing up - alignment when trap precision is instruction. Moreover, we can - only do our job when sched2 is run. */ - if (optimize && !optimize_size - && alpha_tp != ALPHA_TP_INSN - && flag_schedule_insns_after_reload) - { - if (alpha_cpu == PROCESSOR_EV4) - alpha_align_insns (8, alphaev4_next_group, alphaev4_next_nop); - else if (alpha_cpu == PROCESSOR_EV5) - alpha_align_insns (16, alphaev5_next_group, alphaev5_next_nop); - } -} - -#if !TARGET_ABI_UNICOSMK - -#ifdef HAVE_STAMP_H -#include <stamp.h> -#endif - -static void -alpha_file_start (void) -{ -#ifdef OBJECT_FORMAT_ELF - /* If emitting dwarf2 debug information, we cannot generate a .file - directive to start the file, as it will conflict with dwarf2out - file numbers. So it's only useful when emitting mdebug output. */ - targetm.file_start_file_directive = (write_symbols == DBX_DEBUG); -#endif - - default_file_start (); -#ifdef MS_STAMP - fprintf (asm_out_file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP); -#endif - - fputs ("\t.set noreorder\n", asm_out_file); - fputs ("\t.set volatile\n", asm_out_file); - if (!TARGET_ABI_OPEN_VMS) - fputs ("\t.set noat\n", asm_out_file); - if (TARGET_EXPLICIT_RELOCS) - fputs ("\t.set nomacro\n", asm_out_file); - if (TARGET_SUPPORT_ARCH | TARGET_BWX | TARGET_MAX | TARGET_FIX | TARGET_CIX) - fprintf (asm_out_file, - "\t.arch %s\n", - TARGET_CPU_EV6 ? "ev6" - : (TARGET_CPU_EV5 - ? (TARGET_MAX ? "pca56" : TARGET_BWX ? "ev56" : "ev5") - : "ev4")); -} -#endif - -#ifdef OBJECT_FORMAT_ELF - -/* Switch to the section to which we should output X. The only thing - special we do here is to honor small data. */ - -static void -alpha_elf_select_rtx_section (enum machine_mode mode, rtx x, - unsigned HOST_WIDE_INT align) -{ - if (TARGET_SMALL_DATA && GET_MODE_SIZE (mode) <= g_switch_value) - /* ??? Consider using mergeable sdata sections. */ - sdata_section (); - else - default_elf_select_rtx_section (mode, x, align); -} - -#endif /* OBJECT_FORMAT_ELF */ - -/* Structure to collect function names for final output in link section. */ -/* Note that items marked with GTY can't be ifdef'ed out. */ - -enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN}; -enum reloc_kind {KIND_LINKAGE, KIND_CODEADDR}; - -struct alpha_links GTY(()) -{ - int num; - rtx linkage; - enum links_kind lkind; - enum reloc_kind rkind; -}; - -struct alpha_funcs GTY(()) -{ - int num; - splay_tree GTY ((param1_is (char *), param2_is (struct alpha_links *))) - links; -}; - -static GTY ((param1_is (char *), param2_is (struct alpha_links *))) - splay_tree alpha_links_tree; -static GTY ((param1_is (tree), param2_is (struct alpha_funcs *))) - splay_tree alpha_funcs_tree; - -static GTY(()) int alpha_funcs_num; - -#if TARGET_ABI_OPEN_VMS - -/* Return the VMS argument type corresponding to MODE. */ - -enum avms_arg_type -alpha_arg_type (enum machine_mode mode) -{ - switch (mode) - { - case SFmode: - return TARGET_FLOAT_VAX ? FF : FS; - case DFmode: - return TARGET_FLOAT_VAX ? FD : FT; - default: - return I64; - } -} - -/* Return an rtx for an integer representing the VMS Argument Information - register value. */ - -rtx -alpha_arg_info_reg_val (CUMULATIVE_ARGS cum) -{ - unsigned HOST_WIDE_INT regval = cum.num_args; - int i; - - for (i = 0; i < 6; i++) - regval |= ((int) cum.atypes[i]) << (i * 3 + 8); - - return GEN_INT (regval); -} - -/* Make (or fake) .linkage entry for function call. - - IS_LOCAL is 0 if name is used in call, 1 if name is used in definition. - - Return an SYMBOL_REF rtx for the linkage. */ - -rtx -alpha_need_linkage (const char *name, int is_local) -{ - splay_tree_node node; - struct alpha_links *al; - - if (name[0] == '*') - name++; - - if (is_local) - { - struct alpha_funcs *cfaf; - - if (!alpha_funcs_tree) - alpha_funcs_tree = splay_tree_new_ggc ((splay_tree_compare_fn) - splay_tree_compare_pointers); - - cfaf = (struct alpha_funcs *) ggc_alloc (sizeof (struct alpha_funcs)); - - cfaf->links = 0; - cfaf->num = ++alpha_funcs_num; - - splay_tree_insert (alpha_funcs_tree, - (splay_tree_key) current_function_decl, - (splay_tree_value) cfaf); - } - - if (alpha_links_tree) - { - /* Is this name already defined? */ - - node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name); - if (node) - { - al = (struct alpha_links *) node->value; - if (is_local) - { - /* Defined here but external assumed. */ - if (al->lkind == KIND_EXTERN) - al->lkind = KIND_LOCAL; - } - else - { - /* Used here but unused assumed. */ - if (al->lkind == KIND_UNUSED) - al->lkind = KIND_LOCAL; - } - return al->linkage; - } - } - else - alpha_links_tree = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp); - - al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links)); - name = ggc_strdup (name); - - /* Assume external if no definition. */ - al->lkind = (is_local ? KIND_UNUSED : KIND_EXTERN); - - /* Ensure we have an IDENTIFIER so assemble_name can mark it used. */ - get_identifier (name); - - /* Construct a SYMBOL_REF for us to call. */ - { - size_t name_len = strlen (name); - char *linksym = alloca (name_len + 6); - linksym[0] = '$'; - memcpy (linksym + 1, name, name_len); - memcpy (linksym + 1 + name_len, "..lk", 5); - al->linkage = gen_rtx_SYMBOL_REF (Pmode, - ggc_alloc_string (linksym, name_len + 5)); - } - - splay_tree_insert (alpha_links_tree, (splay_tree_key) name, - (splay_tree_value) al); - - return al->linkage; -} - -rtx -alpha_use_linkage (rtx linkage, tree cfundecl, int lflag, int rflag) -{ - splay_tree_node cfunnode; - struct alpha_funcs *cfaf; - struct alpha_links *al; - const char *name = XSTR (linkage, 0); - - cfaf = (struct alpha_funcs *) 0; - al = (struct alpha_links *) 0; - - cfunnode = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) cfundecl); - cfaf = (struct alpha_funcs *) cfunnode->value; - - if (cfaf->links) - { - splay_tree_node lnode; - - /* Is this name already defined? */ - - lnode = splay_tree_lookup (cfaf->links, (splay_tree_key) name); - if (lnode) - al = (struct alpha_links *) lnode->value; - } - else - cfaf->links = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp); - - if (!al) - { - size_t name_len; - size_t buflen; - char buf [512]; - char *linksym; - splay_tree_node node = 0; - struct alpha_links *anl; - - if (name[0] == '*') - name++; - - name_len = strlen (name); - - al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links)); - al->num = cfaf->num; - - node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name); - if (node) - { - anl = (struct alpha_links *) node->value; - al->lkind = anl->lkind; - } - - sprintf (buf, "$%d..%s..lk", cfaf->num, name); - buflen = strlen (buf); - linksym = alloca (buflen + 1); - memcpy (linksym, buf, buflen + 1); - - al->linkage = gen_rtx_SYMBOL_REF - (Pmode, ggc_alloc_string (linksym, buflen + 1)); - - splay_tree_insert (cfaf->links, (splay_tree_key) name, - (splay_tree_value) al); - } - - if (rflag) - al->rkind = KIND_CODEADDR; - else - al->rkind = KIND_LINKAGE; - - if (lflag) - return gen_rtx_MEM (Pmode, plus_constant (al->linkage, 8)); - else - return al->linkage; -} - -static int -alpha_write_one_linkage (splay_tree_node node, void *data) -{ - const char *const name = (const char *) node->key; - struct alpha_links *link = (struct alpha_links *) node->value; - FILE *stream = (FILE *) data; - - fprintf (stream, "$%d..%s..lk:\n", link->num, name); - if (link->rkind == KIND_CODEADDR) - { - if (link->lkind == KIND_LOCAL) - { - /* Local and used */ - fprintf (stream, "\t.quad %s..en\n", name); - } - else - { - /* External and used, request code address. */ - fprintf (stream, "\t.code_address %s\n", name); - } - } - else - { - if (link->lkind == KIND_LOCAL) - { - /* Local and used, build linkage pair. */ - fprintf (stream, "\t.quad %s..en\n", name); - fprintf (stream, "\t.quad %s\n", name); - } - else - { - /* External and used, request linkage pair. */ - fprintf (stream, "\t.linkage %s\n", name); - } - } - - return 0; -} - -static void -alpha_write_linkage (FILE *stream, const char *funname, tree fundecl) -{ - splay_tree_node node; - struct alpha_funcs *func; - - link_section (); - fprintf (stream, "\t.align 3\n"); - node = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) fundecl); - func = (struct alpha_funcs *) node->value; - - fputs ("\t.name ", stream); - assemble_name (stream, funname); - fputs ("..na\n", stream); - ASM_OUTPUT_LABEL (stream, funname); - fprintf (stream, "\t.pdesc "); - assemble_name (stream, funname); - fprintf (stream, "..en,%s\n", - alpha_procedure_type == PT_STACK ? "stack" - : alpha_procedure_type == PT_REGISTER ? "reg" : "null"); - - if (func->links) - { - splay_tree_foreach (func->links, alpha_write_one_linkage, stream); - /* splay_tree_delete (func->links); */ - } -} - -/* Given a decl, a section name, and whether the decl initializer - has relocs, choose attributes for the section. */ - -#define SECTION_VMS_OVERLAY SECTION_FORGET -#define SECTION_VMS_GLOBAL SECTION_MACH_DEP -#define SECTION_VMS_INITIALIZE (SECTION_VMS_GLOBAL << 1) - -static unsigned int -vms_section_type_flags (tree decl, const char *name, int reloc) -{ - unsigned int flags = default_section_type_flags (decl, name, reloc); - - if (decl && DECL_ATTRIBUTES (decl) - && lookup_attribute ("overlaid", DECL_ATTRIBUTES (decl))) - flags |= SECTION_VMS_OVERLAY; - if (decl && DECL_ATTRIBUTES (decl) - && lookup_attribute ("global", DECL_ATTRIBUTES (decl))) - flags |= SECTION_VMS_GLOBAL; - if (decl && DECL_ATTRIBUTES (decl) - && lookup_attribute ("initialize", DECL_ATTRIBUTES (decl))) - flags |= SECTION_VMS_INITIALIZE; - - return flags; -} - -/* Switch to an arbitrary section NAME with attributes as specified - by FLAGS. ALIGN specifies any known alignment requirements for - the section; 0 if the default should be used. */ - -static void -vms_asm_named_section (const char *name, unsigned int flags) -{ - fputc ('\n', asm_out_file); - fprintf (asm_out_file, ".section\t%s", name); - - if (flags & SECTION_VMS_OVERLAY) - fprintf (asm_out_file, ",OVR"); - if (flags & SECTION_VMS_GLOBAL) - fprintf (asm_out_file, ",GBL"); - if (flags & SECTION_VMS_INITIALIZE) - fprintf (asm_out_file, ",NOMOD"); - if (flags & SECTION_DEBUG) - fprintf (asm_out_file, ",NOWRT"); - - fputc ('\n', asm_out_file); -} - -/* Record an element in the table of global constructors. SYMBOL is - a SYMBOL_REF of the function to be called; PRIORITY is a number - between 0 and MAX_INIT_PRIORITY. - - Differs from default_ctors_section_asm_out_constructor in that the - width of the .ctors entry is always 64 bits, rather than the 32 bits - used by a normal pointer. */ - -static void -vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED) -{ - ctors_section (); - assemble_align (BITS_PER_WORD); - assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1); -} - -static void -vms_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED) -{ - dtors_section (); - assemble_align (BITS_PER_WORD); - assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1); -} -#else - -rtx -alpha_need_linkage (const char *name ATTRIBUTE_UNUSED, - int is_local ATTRIBUTE_UNUSED) -{ - return NULL_RTX; -} - -rtx -alpha_use_linkage (rtx linkage ATTRIBUTE_UNUSED, - tree cfundecl ATTRIBUTE_UNUSED, - int lflag ATTRIBUTE_UNUSED, - int rflag ATTRIBUTE_UNUSED) -{ - return NULL_RTX; -} - -#endif /* TARGET_ABI_OPEN_VMS */ - -#if TARGET_ABI_UNICOSMK - -/* Define the offset between two registers, one to be eliminated, and the - other its replacement, at the start of a routine. */ - -int -unicosmk_initial_elimination_offset (int from, int to) -{ - int fixed_size; - - fixed_size = alpha_sa_size(); - if (fixed_size != 0) - fixed_size += 48; - - if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) - return -fixed_size; - else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) - return 0; - else if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) - return (ALPHA_ROUND (current_function_outgoing_args_size) - + ALPHA_ROUND (get_frame_size())); - else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) - return (ALPHA_ROUND (fixed_size) - + ALPHA_ROUND (get_frame_size() - + current_function_outgoing_args_size)); - else - abort (); -} - -/* Output the module name for .ident and .end directives. We have to strip - directories and add make sure that the module name starts with a letter - or '$'. */ - -static void -unicosmk_output_module_name (FILE *file) -{ - const char *name = lbasename (main_input_filename); - unsigned len = strlen (name); - char *clean_name = alloca (len + 2); - char *ptr = clean_name; - - /* CAM only accepts module names that start with a letter or '$'. We - prefix the module name with a '$' if necessary. */ - - if (!ISALPHA (*name)) - *ptr++ = '$'; - memcpy (ptr, name, len + 1); - clean_symbol_name (clean_name); - fputs (clean_name, file); -} - -/* Output the definition of a common variable. */ - -void -unicosmk_output_common (FILE *file, const char *name, int size, int align) -{ - tree name_tree; - printf ("T3E__: common %s\n", name); - - common_section (); - fputs("\t.endp\n\n\t.psect ", file); - assemble_name(file, name); - fprintf(file, ",%d,common\n", floor_log2 (align / BITS_PER_UNIT)); - fprintf(file, "\t.byte\t0:%d\n", size); - - /* Mark the symbol as defined in this module. */ - name_tree = get_identifier (name); - TREE_ASM_WRITTEN (name_tree) = 1; -} - -#define SECTION_PUBLIC SECTION_MACH_DEP -#define SECTION_MAIN (SECTION_PUBLIC << 1) -static int current_section_align; - -static unsigned int -unicosmk_section_type_flags (tree decl, const char *name, - int reloc ATTRIBUTE_UNUSED) -{ - unsigned int flags = default_section_type_flags (decl, name, reloc); - - if (!decl) - return flags; - - if (TREE_CODE (decl) == FUNCTION_DECL) - { - current_section_align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT); - if (align_functions_log > current_section_align) - current_section_align = align_functions_log; - - if (! strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "main")) - flags |= SECTION_MAIN; - } - else - current_section_align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT); - - if (TREE_PUBLIC (decl)) - flags |= SECTION_PUBLIC; - - return flags; -} - -/* Generate a section name for decl and associate it with the - declaration. */ - -static void -unicosmk_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED) -{ - const char *name; - int len; - - if (!decl) - abort (); - - name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); - name = default_strip_name_encoding (name); - len = strlen (name); - - if (TREE_CODE (decl) == FUNCTION_DECL) - { - char *string; - - /* It is essential that we prefix the section name here because - otherwise the section names generated for constructors and - destructors confuse collect2. */ - - string = alloca (len + 6); - sprintf (string, "code@%s", name); - DECL_SECTION_NAME (decl) = build_string (len + 5, string); - } - else if (TREE_PUBLIC (decl)) - DECL_SECTION_NAME (decl) = build_string (len, name); - else - { - char *string; - - string = alloca (len + 6); - sprintf (string, "data@%s", name); - DECL_SECTION_NAME (decl) = build_string (len + 5, string); - } -} - -/* Switch to an arbitrary section NAME with attributes as specified - by FLAGS. ALIGN specifies any known alignment requirements for - the section; 0 if the default should be used. */ - -static void -unicosmk_asm_named_section (const char *name, unsigned int flags) -{ - const char *kind; - - /* Close the previous section. */ - - fputs ("\t.endp\n\n", asm_out_file); - - /* Find out what kind of section we are opening. */ - - if (flags & SECTION_MAIN) - fputs ("\t.start\tmain\n", asm_out_file); - - if (flags & SECTION_CODE) - kind = "code"; - else if (flags & SECTION_PUBLIC) - kind = "common"; - else - kind = "data"; - - if (current_section_align != 0) - fprintf (asm_out_file, "\t.psect\t%s,%d,%s\n", name, - current_section_align, kind); - else - fprintf (asm_out_file, "\t.psect\t%s,%s\n", name, kind); -} - -static void -unicosmk_insert_attributes (tree decl, tree *attr_ptr ATTRIBUTE_UNUSED) -{ - if (DECL_P (decl) - && (TREE_PUBLIC (decl) || TREE_CODE (decl) == FUNCTION_DECL)) - unicosmk_unique_section (decl, 0); -} - -/* Output an alignment directive. We have to use the macro 'gcc@code@align' - in code sections because .align fill unused space with zeroes. */ - -void -unicosmk_output_align (FILE *file, int align) -{ - if (inside_function) - fprintf (file, "\tgcc@code@align\t%d\n", align); - else - fprintf (file, "\t.align\t%d\n", align); -} - -/* Add a case vector to the current function's list of deferred case - vectors. Case vectors have to be put into a separate section because CAM - does not allow data definitions in code sections. */ - -void -unicosmk_defer_case_vector (rtx lab, rtx vec) -{ - struct machine_function *machine = cfun->machine; - - vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec); - machine->addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec, - machine->addr_list); -} - -/* Output a case vector. */ - -static void -unicosmk_output_addr_vec (FILE *file, rtx vec) -{ - rtx lab = XEXP (vec, 0); - rtx body = XEXP (vec, 1); - int vlen = XVECLEN (body, 0); - int idx; - - (*targetm.asm_out.internal_label) (file, "L", CODE_LABEL_NUMBER (lab)); - - for (idx = 0; idx < vlen; idx++) - { - ASM_OUTPUT_ADDR_VEC_ELT - (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0))); - } -} - -/* Output current function's deferred case vectors. */ - -static void -unicosmk_output_deferred_case_vectors (FILE *file) -{ - struct machine_function *machine = cfun->machine; - rtx t; - - if (machine->addr_list == NULL_RTX) - return; - - data_section (); - for (t = machine->addr_list; t; t = XEXP (t, 1)) - unicosmk_output_addr_vec (file, XEXP (t, 0)); -} - -/* Generate the name of the SSIB section for the current function. */ - -#define SSIB_PREFIX "__SSIB_" -#define SSIB_PREFIX_LEN 7 - -static const char * -unicosmk_ssib_name (void) -{ - /* This is ok since CAM won't be able to deal with names longer than that - anyway. */ - - static char name[256]; - - rtx x; - const char *fnname; - int len; - - x = DECL_RTL (cfun->decl); - if (GET_CODE (x) != MEM) - abort (); - x = XEXP (x, 0); - if (GET_CODE (x) != SYMBOL_REF) - abort (); - fnname = XSTR (x, 0); - - len = strlen (fnname); - if (len + SSIB_PREFIX_LEN > 255) - len = 255 - SSIB_PREFIX_LEN; - - strcpy (name, SSIB_PREFIX); - strncpy (name + SSIB_PREFIX_LEN, fnname, len); - name[len + SSIB_PREFIX_LEN] = 0; - - return name; -} - -/* Set up the dynamic subprogram information block (DSIB) and update the - frame pointer register ($15) for subroutines which have a frame. If the - subroutine doesn't have a frame, simply increment $15. */ - -static void -unicosmk_gen_dsib (unsigned long *imaskP) -{ - if (alpha_procedure_type == PT_STACK) - { - const char *ssib_name; - rtx mem; - - /* Allocate 64 bytes for the DSIB. */ - - FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx, - GEN_INT (-64)))); - emit_insn (gen_blockage ()); - - /* Save the return address. */ - - mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 56)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA))); - (*imaskP) &= ~(1UL << REG_RA); - - /* Save the old frame pointer. */ - - mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 48)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (mem, hard_frame_pointer_rtx)); - (*imaskP) &= ~(1UL << HARD_FRAME_POINTER_REGNUM); - - emit_insn (gen_blockage ()); - - /* Store the SSIB pointer. */ - - ssib_name = ggc_strdup (unicosmk_ssib_name ()); - mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 32)); - set_mem_alias_set (mem, alpha_sr_alias_set); - - FRP (emit_move_insn (gen_rtx_REG (DImode, 5), - gen_rtx_SYMBOL_REF (Pmode, ssib_name))); - FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 5))); - - /* Save the CIW index. */ - - mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 24)); - set_mem_alias_set (mem, alpha_sr_alias_set); - FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 25))); - - emit_insn (gen_blockage ()); - - /* Set the new frame pointer. */ - - FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx, - stack_pointer_rtx, GEN_INT (64)))); - - } - else - { - /* Increment the frame pointer register to indicate that we do not - have a frame. */ - - FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx, - hard_frame_pointer_rtx, GEN_INT (1)))); - } -} - -/* Output the static subroutine information block for the current - function. */ - -static void -unicosmk_output_ssib (FILE *file, const char *fnname) -{ - int len; - int i; - rtx x; - rtx ciw; - struct machine_function *machine = cfun->machine; - - ssib_section (); - fprintf (file, "\t.endp\n\n\t.psect\t%s%s,data\n", user_label_prefix, - unicosmk_ssib_name ()); - - /* Some required stuff and the function name length. */ - - len = strlen (fnname); - fprintf (file, "\t.quad\t^X20008%2.2X28\n", len); - - /* Saved registers - ??? We don't do that yet. */ - - fputs ("\t.quad\t0\n", file); - - /* Function address. */ - - fputs ("\t.quad\t", file); - assemble_name (file, fnname); - putc ('\n', file); - - fputs ("\t.quad\t0\n", file); - fputs ("\t.quad\t0\n", file); - - /* Function name. - ??? We do it the same way Cray CC does it but this could be - simplified. */ - - for( i = 0; i < len; i++ ) - fprintf (file, "\t.byte\t%d\n", (int)(fnname[i])); - if( (len % 8) == 0 ) - fputs ("\t.quad\t0\n", file); - else - fprintf (file, "\t.bits\t%d : 0\n", (8 - (len % 8))*8); - - /* All call information words used in the function. */ - - for (x = machine->first_ciw; x; x = XEXP (x, 1)) - { - ciw = XEXP (x, 0); -#if HOST_BITS_PER_WIDE_INT == 32 - fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_DOUBLE_HEX "\n", - CONST_DOUBLE_HIGH (ciw), CONST_DOUBLE_LOW (ciw)); -#else - fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX "\n", INTVAL (ciw)); -#endif - } -} - -/* Add a call information word (CIW) to the list of the current function's - CIWs and return its index. - - X is a CONST_INT or CONST_DOUBLE representing the CIW. */ - -rtx -unicosmk_add_call_info_word (rtx x) -{ - rtx node; - struct machine_function *machine = cfun->machine; - - node = gen_rtx_EXPR_LIST (VOIDmode, x, NULL_RTX); - if (machine->first_ciw == NULL_RTX) - machine->first_ciw = node; - else - XEXP (machine->last_ciw, 1) = node; - - machine->last_ciw = node; - ++machine->ciw_count; - - return GEN_INT (machine->ciw_count - + strlen (current_function_name ())/8 + 5); -} - -static char unicosmk_section_buf[100]; - -char * -unicosmk_text_section (void) -{ - static int count = 0; - sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@text___%d,code", - count++); - return unicosmk_section_buf; -} - -char * -unicosmk_data_section (void) -{ - static int count = 1; - sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@data___%d,data", - count++); - return unicosmk_section_buf; -} - -/* The Cray assembler doesn't accept extern declarations for symbols which - are defined in the same file. We have to keep track of all global - symbols which are referenced and/or defined in a source file and output - extern declarations for those which are referenced but not defined at - the end of file. */ - -/* List of identifiers for which an extern declaration might have to be - emitted. */ -/* FIXME: needs to use GC, so it can be saved and restored for PCH. */ - -struct unicosmk_extern_list -{ - struct unicosmk_extern_list *next; - const char *name; -}; - -static struct unicosmk_extern_list *unicosmk_extern_head = 0; - -/* Output extern declarations which are required for every asm file. */ - -static void -unicosmk_output_default_externs (FILE *file) -{ - static const char *const externs[] = - { "__T3E_MISMATCH" }; - - int i; - int n; - - n = ARRAY_SIZE (externs); - - for (i = 0; i < n; i++) - fprintf (file, "\t.extern\t%s\n", externs[i]); -} - -/* Output extern declarations for global symbols which are have been - referenced but not defined. */ - -static void -unicosmk_output_externs (FILE *file) -{ - struct unicosmk_extern_list *p; - const char *real_name; - int len; - tree name_tree; - - len = strlen (user_label_prefix); - for (p = unicosmk_extern_head; p != 0; p = p->next) - { - /* We have to strip the encoding and possibly remove user_label_prefix - from the identifier in order to handle -fleading-underscore and - explicit asm names correctly (cf. gcc.dg/asm-names-1.c). */ - real_name = default_strip_name_encoding (p->name); - if (len && p->name[0] == '*' - && !memcmp (real_name, user_label_prefix, len)) - real_name += len; - - name_tree = get_identifier (real_name); - if (! TREE_ASM_WRITTEN (name_tree)) - { - TREE_ASM_WRITTEN (name_tree) = 1; - fputs ("\t.extern\t", file); - assemble_name (file, p->name); - putc ('\n', file); - } - } -} - -/* Record an extern. */ - -void -unicosmk_add_extern (const char *name) -{ - struct unicosmk_extern_list *p; - - p = (struct unicosmk_extern_list *) - xmalloc (sizeof (struct unicosmk_extern_list)); - p->next = unicosmk_extern_head; - p->name = name; - unicosmk_extern_head = p; -} - -/* The Cray assembler generates incorrect code if identifiers which - conflict with register names are used as instruction operands. We have - to replace such identifiers with DEX expressions. */ - -/* Structure to collect identifiers which have been replaced by DEX - expressions. */ -/* FIXME: needs to use GC, so it can be saved and restored for PCH. */ - -struct unicosmk_dex { - struct unicosmk_dex *next; - const char *name; -}; - -/* List of identifiers which have been replaced by DEX expressions. The DEX - number is determined by the position in the list. */ - -static struct unicosmk_dex *unicosmk_dex_list = NULL; - -/* The number of elements in the DEX list. */ - -static int unicosmk_dex_count = 0; - -/* Check if NAME must be replaced by a DEX expression. */ - -static int -unicosmk_special_name (const char *name) -{ - if (name[0] == '*') - ++name; - - if (name[0] == '$') - ++name; - - if (name[0] != 'r' && name[0] != 'f' && name[0] != 'R' && name[0] != 'F') - return 0; - - switch (name[1]) - { - case '1': case '2': - return (name[2] == '\0' || (ISDIGIT (name[2]) && name[3] == '\0')); - - case '3': - return (name[2] == '\0' - || ((name[2] == '0' || name[2] == '1') && name[3] == '\0')); - - default: - return (ISDIGIT (name[1]) && name[2] == '\0'); - } -} - -/* Return the DEX number if X must be replaced by a DEX expression and 0 - otherwise. */ - -static int -unicosmk_need_dex (rtx x) -{ - struct unicosmk_dex *dex; - const char *name; - int i; - - if (GET_CODE (x) != SYMBOL_REF) - return 0; - - name = XSTR (x,0); - if (! unicosmk_special_name (name)) - return 0; - - i = unicosmk_dex_count; - for (dex = unicosmk_dex_list; dex; dex = dex->next) - { - if (! strcmp (name, dex->name)) - return i; - --i; - } - - dex = (struct unicosmk_dex *) xmalloc (sizeof (struct unicosmk_dex)); - dex->name = name; - dex->next = unicosmk_dex_list; - unicosmk_dex_list = dex; - - ++unicosmk_dex_count; - return unicosmk_dex_count; -} - -/* Output the DEX definitions for this file. */ - -static void -unicosmk_output_dex (FILE *file) -{ - struct unicosmk_dex *dex; - int i; - - if (unicosmk_dex_list == NULL) - return; - - fprintf (file, "\t.dexstart\n"); - - i = unicosmk_dex_count; - for (dex = unicosmk_dex_list; dex; dex = dex->next) - { - fprintf (file, "\tDEX (%d) = ", i); - assemble_name (file, dex->name); - putc ('\n', file); - --i; - } - - fprintf (file, "\t.dexend\n"); -} - -/* Output text that to appear at the beginning of an assembler file. */ - -static void -unicosmk_file_start (void) -{ - int i; - - fputs ("\t.ident\t", asm_out_file); - unicosmk_output_module_name (asm_out_file); - fputs ("\n\n", asm_out_file); - - /* The Unicos/Mk assembler uses different register names. Instead of trying - to support them, we simply use micro definitions. */ - - /* CAM has different register names: rN for the integer register N and fN - for the floating-point register N. Instead of trying to use these in - alpha.md, we define the symbols $N and $fN to refer to the appropriate - register. */ - - for (i = 0; i < 32; ++i) - fprintf (asm_out_file, "$%d <- r%d\n", i, i); - - for (i = 0; i < 32; ++i) - fprintf (asm_out_file, "$f%d <- f%d\n", i, i); - - putc ('\n', asm_out_file); - - /* The .align directive fill unused space with zeroes which does not work - in code sections. We define the macro 'gcc@code@align' which uses nops - instead. Note that it assumes that code sections always have the - biggest possible alignment since . refers to the current offset from - the beginning of the section. */ - - fputs ("\t.macro gcc@code@align n\n", asm_out_file); - fputs ("gcc@n@bytes = 1 << n\n", asm_out_file); - fputs ("gcc@here = . % gcc@n@bytes\n", asm_out_file); - fputs ("\t.if ne, gcc@here, 0\n", asm_out_file); - fputs ("\t.repeat (gcc@n@bytes - gcc@here) / 4\n", asm_out_file); - fputs ("\tbis r31,r31,r31\n", asm_out_file); - fputs ("\t.endr\n", asm_out_file); - fputs ("\t.endif\n", asm_out_file); - fputs ("\t.endm gcc@code@align\n\n", asm_out_file); - - /* Output extern declarations which should always be visible. */ - unicosmk_output_default_externs (asm_out_file); - - /* Open a dummy section. We always need to be inside a section for the - section-switching code to work correctly. - ??? This should be a module id or something like that. I still have to - figure out what the rules for those are. */ - fputs ("\n\t.psect\t$SG00000,data\n", asm_out_file); -} - -/* Output text to appear at the end of an assembler file. This includes all - pending extern declarations and DEX expressions. */ - -static void -unicosmk_file_end (void) -{ - fputs ("\t.endp\n\n", asm_out_file); - - /* Output all pending externs. */ - - unicosmk_output_externs (asm_out_file); - - /* Output dex definitions used for functions whose names conflict with - register names. */ - - unicosmk_output_dex (asm_out_file); - - fputs ("\t.end\t", asm_out_file); - unicosmk_output_module_name (asm_out_file); - putc ('\n', asm_out_file); -} - -#else - -static void -unicosmk_output_deferred_case_vectors (FILE *file ATTRIBUTE_UNUSED) -{} - -static void -unicosmk_gen_dsib (unsigned long *imaskP ATTRIBUTE_UNUSED) -{} - -static void -unicosmk_output_ssib (FILE * file ATTRIBUTE_UNUSED, - const char * fnname ATTRIBUTE_UNUSED) -{} - -rtx -unicosmk_add_call_info_word (rtx x ATTRIBUTE_UNUSED) -{ - return NULL_RTX; -} - -static int -unicosmk_need_dex (rtx x ATTRIBUTE_UNUSED) -{ - return 0; -} - -#endif /* TARGET_ABI_UNICOSMK */ - -static void -alpha_init_libfuncs (void) -{ - if (TARGET_ABI_UNICOSMK) - { - /* Prevent gcc from generating calls to __divsi3. */ - set_optab_libfunc (sdiv_optab, SImode, 0); - set_optab_libfunc (udiv_optab, SImode, 0); - - /* Use the functions provided by the system library - for DImode integer division. */ - set_optab_libfunc (sdiv_optab, DImode, "$sldiv"); - set_optab_libfunc (udiv_optab, DImode, "$uldiv"); - } - else if (TARGET_ABI_OPEN_VMS) - { - /* Use the VMS runtime library functions for division and - remainder. */ - set_optab_libfunc (sdiv_optab, SImode, "OTS$DIV_I"); - set_optab_libfunc (sdiv_optab, DImode, "OTS$DIV_L"); - set_optab_libfunc (udiv_optab, SImode, "OTS$DIV_UI"); - set_optab_libfunc (udiv_optab, DImode, "OTS$DIV_UL"); - set_optab_libfunc (smod_optab, SImode, "OTS$REM_I"); - set_optab_libfunc (smod_optab, DImode, "OTS$REM_L"); - set_optab_libfunc (umod_optab, SImode, "OTS$REM_UI"); - set_optab_libfunc (umod_optab, DImode, "OTS$REM_UL"); - } -} - - -/* Initialize the GCC target structure. */ -#if TARGET_ABI_OPEN_VMS -# undef TARGET_ATTRIBUTE_TABLE -# define TARGET_ATTRIBUTE_TABLE vms_attribute_table -# undef TARGET_SECTION_TYPE_FLAGS -# define TARGET_SECTION_TYPE_FLAGS vms_section_type_flags -#endif - -#undef TARGET_IN_SMALL_DATA_P -#define TARGET_IN_SMALL_DATA_P alpha_in_small_data_p - -#if TARGET_ABI_UNICOSMK -# undef TARGET_INSERT_ATTRIBUTES -# define TARGET_INSERT_ATTRIBUTES unicosmk_insert_attributes -# undef TARGET_SECTION_TYPE_FLAGS -# define TARGET_SECTION_TYPE_FLAGS unicosmk_section_type_flags -# undef TARGET_ASM_UNIQUE_SECTION -# define TARGET_ASM_UNIQUE_SECTION unicosmk_unique_section -# undef TARGET_ASM_GLOBALIZE_LABEL -# define TARGET_ASM_GLOBALIZE_LABEL hook_void_FILEptr_constcharptr -#endif - -#undef TARGET_ASM_ALIGNED_HI_OP -#define TARGET_ASM_ALIGNED_HI_OP "\t.word\t" -#undef TARGET_ASM_ALIGNED_DI_OP -#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t" - -/* Default unaligned ops are provided for ELF systems. To get unaligned - data for non-ELF systems, we have to turn off auto alignment. */ -#ifndef OBJECT_FORMAT_ELF -#undef TARGET_ASM_UNALIGNED_HI_OP -#define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.word\t" -#undef TARGET_ASM_UNALIGNED_SI_OP -#define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.long\t" -#undef TARGET_ASM_UNALIGNED_DI_OP -#define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.quad\t" -#endif - -#ifdef OBJECT_FORMAT_ELF -#undef TARGET_ASM_SELECT_RTX_SECTION -#define TARGET_ASM_SELECT_RTX_SECTION alpha_elf_select_rtx_section -#endif - -#undef TARGET_ASM_FUNCTION_END_PROLOGUE -#define TARGET_ASM_FUNCTION_END_PROLOGUE alpha_output_function_end_prologue - -#undef TARGET_INIT_LIBFUNCS -#define TARGET_INIT_LIBFUNCS alpha_init_libfuncs - -#if TARGET_ABI_UNICOSMK -#undef TARGET_ASM_FILE_START -#define TARGET_ASM_FILE_START unicosmk_file_start -#undef TARGET_ASM_FILE_END -#define TARGET_ASM_FILE_END unicosmk_file_end -#else -#undef TARGET_ASM_FILE_START -#define TARGET_ASM_FILE_START alpha_file_start -#undef TARGET_ASM_FILE_START_FILE_DIRECTIVE -#define TARGET_ASM_FILE_START_FILE_DIRECTIVE true -#endif - -#undef TARGET_SCHED_ADJUST_COST -#define TARGET_SCHED_ADJUST_COST alpha_adjust_cost -#undef TARGET_SCHED_ISSUE_RATE -#define TARGET_SCHED_ISSUE_RATE alpha_issue_rate -#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE -#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE \ - alpha_use_dfa_pipeline_interface -#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD -#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \ - alpha_multipass_dfa_lookahead - -#undef TARGET_HAVE_TLS -#define TARGET_HAVE_TLS HAVE_AS_TLS - -#undef TARGET_INIT_BUILTINS -#define TARGET_INIT_BUILTINS alpha_init_builtins -#undef TARGET_EXPAND_BUILTIN -#define TARGET_EXPAND_BUILTIN alpha_expand_builtin - -#undef TARGET_FUNCTION_OK_FOR_SIBCALL -#define TARGET_FUNCTION_OK_FOR_SIBCALL alpha_function_ok_for_sibcall -#undef TARGET_CANNOT_COPY_INSN_P -#define TARGET_CANNOT_COPY_INSN_P alpha_cannot_copy_insn_p -#undef TARGET_CANNOT_FORCE_CONST_MEM -#define TARGET_CANNOT_FORCE_CONST_MEM alpha_cannot_force_const_mem - -#if TARGET_ABI_OSF -#undef TARGET_ASM_OUTPUT_MI_THUNK -#define TARGET_ASM_OUTPUT_MI_THUNK alpha_output_mi_thunk_osf -#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK -#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true -#endif - -#undef TARGET_RTX_COSTS -#define TARGET_RTX_COSTS alpha_rtx_costs -#undef TARGET_ADDRESS_COST -#define TARGET_ADDRESS_COST hook_int_rtx_0 - -#undef TARGET_MACHINE_DEPENDENT_REORG -#define TARGET_MACHINE_DEPENDENT_REORG alpha_reorg - -#undef TARGET_PROMOTE_FUNCTION_ARGS -#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true -#undef TARGET_PROMOTE_FUNCTION_RETURN -#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true -#undef TARGET_PROMOTE_PROTOTYPES -#define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_false -#undef TARGET_STRUCT_VALUE_RTX -#define TARGET_STRUCT_VALUE_RTX hook_rtx_tree_int_null -#undef TARGET_RETURN_IN_MEMORY -#define TARGET_RETURN_IN_MEMORY alpha_return_in_memory -#undef TARGET_SETUP_INCOMING_VARARGS -#define TARGET_SETUP_INCOMING_VARARGS alpha_setup_incoming_varargs -#undef TARGET_STRICT_ARGUMENT_NAMING -#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true -#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED -#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true -#undef TARGET_SPLIT_COMPLEX_ARG -#define TARGET_SPLIT_COMPLEX_ARG alpha_split_complex_arg - -#undef TARGET_BUILD_BUILTIN_VA_LIST -#define TARGET_BUILD_BUILTIN_VA_LIST alpha_build_builtin_va_list - -struct gcc_target targetm = TARGET_INITIALIZER; - - -#include "gt-alpha.h" diff --git a/contrib/gcc/config/alpha/elf.h b/contrib/gcc/config/alpha/elf.h deleted file mode 100644 index 97b15fe..0000000 --- a/contrib/gcc/config/alpha/elf.h +++ /dev/null @@ -1,459 +0,0 @@ -/* Definitions of target machine for GNU compiler, for DEC Alpha w/ELF. - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 - Free Software Foundation, Inc. - Contributed by Richard Henderson (rth@tamu.edu). - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -#undef OBJECT_FORMAT_COFF -#undef EXTENDED_COFF -#define OBJECT_FORMAT_ELF 1 - -/* ??? Move all SDB stuff from alpha.h to osf.h. */ -#undef SDB_DEBUGGING_INFO - -#define DBX_DEBUGGING_INFO 1 -#define DWARF2_DEBUGGING_INFO 1 - -#undef PREFERRED_DEBUGGING_TYPE -#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG - -#undef ASM_FINAL_SPEC - -/* alpha/ doesn't use elfos.h for some reason. */ -#define TARGET_OBJFMT_CPP_BUILTINS() \ - do \ - { \ - builtin_define ("__ELF__"); \ - } \ - while (0) - -#undef CC1_SPEC -#define CC1_SPEC "%{G*}" - -#undef ASM_SPEC -#define ASM_SPEC "%{G*} %{relax:-relax} %{!gstabs*:-no-mdebug}%{gstabs*:-mdebug}" - -#undef IDENT_ASM_OP -#define IDENT_ASM_OP "\t.ident\t" - -/* Output #ident as a .ident. */ -#undef ASM_OUTPUT_IDENT -#define ASM_OUTPUT_IDENT(FILE, NAME) \ - fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME); - -/* This is how to allocate empty space in some section. The .zero - pseudo-op is used for this on most svr4 assemblers. */ - -#undef SKIP_ASM_OP -#define SKIP_ASM_OP "\t.zero\t" - -#undef ASM_OUTPUT_SKIP -#define ASM_OUTPUT_SKIP(FILE, SIZE) \ - fprintf (FILE, "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n", SKIP_ASM_OP, (SIZE)) - -/* Output the label which precedes a jumptable. Note that for all svr4 - systems where we actually generate jumptables (which is to say every - svr4 target except i386, where we use casesi instead) we put the jump- - tables into the .rodata section and since other stuff could have been - put into the .rodata section prior to any given jumptable, we have to - make sure that the location counter for the .rodata section gets pro- - perly re-aligned prior to the actual beginning of the jump table. */ - -#undef ALIGN_ASM_OP -#define ALIGN_ASM_OP "\t.align\t" - -#ifndef ASM_OUTPUT_BEFORE_CASE_LABEL -#define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \ - ASM_OUTPUT_ALIGN ((FILE), 2); -#endif - -#undef ASM_OUTPUT_CASE_LABEL -#define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \ - do { \ - ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \ - (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); \ - } while (0) - -/* The standard SVR4 assembler seems to require that certain builtin - library routines (e.g. .udiv) be explicitly declared as .globl - in each assembly file where they are referenced. */ - -#undef ASM_OUTPUT_EXTERNAL_LIBCALL -#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \ - (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0)) - -/* This says how to output assembler code to declare an - uninitialized external linkage data object. Under SVR4, - the linker seems to want the alignment of data objects - to depend on their types. We do exactly that here. */ - -#undef COMMON_ASM_OP -#define COMMON_ASM_OP "\t.comm\t" - -#undef ASM_OUTPUT_ALIGNED_COMMON -#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \ -do { \ - fprintf ((FILE), "%s", COMMON_ASM_OP); \ - assemble_name ((FILE), (NAME)); \ - fprintf ((FILE), "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \ -} while (0) - -/* This says how to output assembler code to declare an - uninitialized internal linkage data object. Under SVR4, - the linker seems to want the alignment of data objects - to depend on their types. We do exactly that here. */ - -#undef ASM_OUTPUT_ALIGNED_LOCAL -#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \ -do { \ - if ((SIZE) <= g_switch_value) \ - sbss_section(); \ - else \ - bss_section(); \ - ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \ - if (!flag_inhibit_size_directive) \ - ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, SIZE); \ - ASM_OUTPUT_ALIGN ((FILE), exact_log2((ALIGN) / BITS_PER_UNIT)); \ - ASM_OUTPUT_LABEL(FILE, NAME); \ - ASM_OUTPUT_SKIP((FILE), (SIZE) ? (SIZE) : 1); \ -} while (0) - -/* This says how to output assembler code to declare an - uninitialized external linkage data object. */ - -#undef ASM_OUTPUT_ALIGNED_BSS -#define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \ -do { \ - ASM_OUTPUT_ALIGNED_LOCAL (FILE, NAME, SIZE, ALIGN); \ -} while (0) - -/* Biggest alignment supported by the object file format of this - machine. Use this macro to limit the alignment which can be - specified using the `__attribute__ ((aligned (N)))' construct. If - not defined, the default value is `BIGGEST_ALIGNMENT'. - - This value is really 2^63. Since gcc figures the alignment in bits, - we could only potentially get to 2^60 on suitable hosts. Due to other - considerations in varasm, we must restrict this to what fits in an int. */ - -#undef MAX_OFILE_ALIGNMENT -#define MAX_OFILE_ALIGNMENT \ - (1 << (HOST_BITS_PER_INT < 64 ? HOST_BITS_PER_INT - 2 : 62)) - -/* This is the pseudo-op used to generate a contiguous sequence of byte - values from a double-quoted string WITHOUT HAVING A TERMINATING NUL - AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */ - -#undef ASCII_DATA_ASM_OP -#define ASCII_DATA_ASM_OP "\t.ascii\t" - -#undef READONLY_DATA_SECTION_ASM_OP -#define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata" -#undef BSS_SECTION_ASM_OP -#define BSS_SECTION_ASM_OP "\t.section\t.bss" -#undef SBSS_SECTION_ASM_OP -#define SBSS_SECTION_ASM_OP "\t.section\t.sbss,\"aw\"" -#undef SDATA_SECTION_ASM_OP -#define SDATA_SECTION_ASM_OP "\t.section\t.sdata,\"aw\"" - -/* On svr4, we *do* have support for the .init and .fini sections, and we - can put stuff in there to be executed before and after `main'. We let - crtstuff.c and other files know this by defining the following symbols. - The definitions say how to change sections to the .init and .fini - sections. This is the same for all known svr4 assemblers. */ - -#undef INIT_SECTION_ASM_OP -#define INIT_SECTION_ASM_OP "\t.section\t.init" -#undef FINI_SECTION_ASM_OP -#define FINI_SECTION_ASM_OP "\t.section\t.fini" - -#ifdef HAVE_GAS_SUBSECTION_ORDERING - -#define ASM_SECTION_START_OP "\t.subsection\t-1" - -/* Output assembly directive to move to the beginning of current section. */ -#define ASM_OUTPUT_SECTION_START(FILE) \ - fprintf ((FILE), "%s\n", ASM_SECTION_START_OP) - -#endif - -/* A default list of other sections which we might be "in" at any given - time. For targets that use additional sections (e.g. .tdesc) you - should override this definition in the target-specific file which - includes this file. */ - -#undef EXTRA_SECTIONS -#define EXTRA_SECTIONS in_sbss, in_sdata - -/* A default list of extra section function definitions. For targets - that use additional sections (e.g. .tdesc) you should override this - definition in the target-specific file which includes this file. */ - -#undef EXTRA_SECTION_FUNCTIONS -#define EXTRA_SECTION_FUNCTIONS \ - SECTION_FUNCTION_TEMPLATE(sbss_section, in_sbss, SBSS_SECTION_ASM_OP) \ - SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) - -extern void sbss_section (void); -extern void sdata_section (void); - -#undef SECTION_FUNCTION_TEMPLATE -#define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP) \ -void FN (void) \ -{ \ - if (in_section != ENUM) \ - { \ - fprintf (asm_out_file, "%s\n", OP); \ - in_section = ENUM; \ - } \ -} - -/* Switch into a generic section. */ -#define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section -#define TARGET_ASM_SELECT_SECTION default_elf_select_section - -#define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1) - -/* Define the strings used for the special svr4 .type and .size directives. - These strings generally do not vary from one system running svr4 to - another, but if a given system (e.g. m88k running svr) needs to use - different pseudo-op names for these, they may be overridden in the - file which includes this one. */ - -#undef TYPE_ASM_OP -#define TYPE_ASM_OP "\t.type\t" -#undef SIZE_ASM_OP -#define SIZE_ASM_OP "\t.size\t" - -/* This is how we tell the assembler that a symbol is weak. */ - -#undef ASM_WEAKEN_LABEL -#define ASM_WEAKEN_LABEL(FILE, NAME) \ - do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \ - fputc ('\n', FILE); } while (0) - -/* This is how we tell the assembler that two symbols have the same value. */ - -#undef ASM_OUTPUT_DEF -#define ASM_OUTPUT_DEF(FILE, ALIAS, NAME) \ - do { \ - assemble_name(FILE, ALIAS); \ - fputs(" = ", FILE); \ - assemble_name(FILE, NAME); \ - fputc('\n', FILE); \ - } while (0) - -#undef ASM_OUTPUT_DEF_FROM_DECLS -#define ASM_OUTPUT_DEF_FROM_DECLS(FILE, DECL, TARGET) \ - do { \ - const char *alias = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ - const char *name = IDENTIFIER_POINTER (TARGET); \ - if (TREE_CODE (DECL) == FUNCTION_DECL) \ - { \ - fputc ('$', FILE); \ - assemble_name (FILE, alias); \ - fputs ("..ng = $", FILE); \ - assemble_name (FILE, name); \ - fputs ("..ng\n", FILE); \ - } \ - assemble_name(FILE, alias); \ - fputs(" = ", FILE); \ - assemble_name(FILE, name); \ - fputc('\n', FILE); \ - } while (0) - -/* The following macro defines the format used to output the second - operand of the .type assembler directive. Different svr4 assemblers - expect various different forms for this operand. The one given here - is just a default. You may need to override it in your machine- - specific tm.h file (depending upon the particulars of your assembler). */ - -#undef TYPE_OPERAND_FMT -#define TYPE_OPERAND_FMT "@%s" - -/* Write the extra assembler code needed to declare a function's result. - Most svr4 assemblers don't require any special declaration of the - result value, but there are exceptions. */ - -#ifndef ASM_DECLARE_RESULT -#define ASM_DECLARE_RESULT(FILE, RESULT) -#endif - -/* These macros generate the special .type and .size directives which - are used to set the corresponding fields of the linker symbol table - entries in an ELF object file under SVR4. These macros also output - the starting labels for the relevant functions/objects. */ - -/* Write the extra assembler code needed to declare an object properly. */ - -#undef ASM_DECLARE_OBJECT_NAME -#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ - do { \ - HOST_WIDE_INT size; \ - ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \ - size_directive_output = 0; \ - if (!flag_inhibit_size_directive \ - && DECL_SIZE (DECL) \ - && (size = int_size_in_bytes (TREE_TYPE (DECL))) > 0) \ - { \ - size_directive_output = 1; \ - ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \ - } \ - ASM_OUTPUT_LABEL(FILE, NAME); \ - } while (0) - -/* Output the size directive for a decl in rest_of_decl_compilation - in the case where we did not do so before the initializer. - Once we find the error_mark_node, we know that the value of - size_directive_output was set - by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ - -#undef ASM_FINISH_DECLARE_OBJECT -#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \ - do { \ - const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ - HOST_WIDE_INT size; \ - if (!flag_inhibit_size_directive \ - && DECL_SIZE (DECL) \ - && ! AT_END && TOP_LEVEL \ - && DECL_INITIAL (DECL) == error_mark_node \ - && !size_directive_output \ - && (size = int_size_in_bytes (TREE_TYPE (DECL))) > 0) \ - { \ - size_directive_output = 1; \ - ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size); \ - } \ - } while (0) - -/* A table of bytes codes used by the ASM_OUTPUT_ASCII and - ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table - corresponds to a particular byte value [0..255]. For any - given byte value, if the value in the corresponding table - position is zero, the given character can be output directly. - If the table value is 1, the byte must be output as a \ooo - octal escape. If the tables value is anything else, then the - byte value should be output as a \ followed by the value - in the table. Note that we can use standard UN*X escape - sequences for many control characters, but we don't use - \a to represent BEL because some svr4 assemblers (e.g. on - the i386) don't know about that. Also, we don't use \v - since some versions of gas, such as 2.2 did not accept it. */ - -#undef ESCAPES -#define ESCAPES \ -"\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ -\0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ -\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\ -\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\ -\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ -\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ -\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ -\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1" - -/* Some svr4 assemblers have a limit on the number of characters which - can appear in the operand of a .string directive. If your assembler - has such a limitation, you should define STRING_LIMIT to reflect that - limit. Note that at least some svr4 assemblers have a limit on the - actual number of bytes in the double-quoted string, and that they - count each character in an escape sequence as one byte. Thus, an - escape sequence like \377 would count as four bytes. - - If your target assembler doesn't support the .string directive, you - should define this to zero. */ - -#undef STRING_LIMIT -#define STRING_LIMIT ((unsigned) 256) -#undef STRING_ASM_OP -#define STRING_ASM_OP "\t.string\t" - -/* GAS is the only Alpha/ELF assembler. */ -#undef TARGET_GAS -#define TARGET_GAS (1) - -/* Provide a STARTFILE_SPEC appropriate for ELF. Here we add the - (even more) magical crtbegin.o file which provides part of the - support for getting C++ file-scope static object constructed - before entering `main'. */ - -#undef STARTFILE_SPEC -#ifdef HAVE_LD_PIE -#define STARTFILE_SPEC \ - "%{!shared: %{pg|p:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}}\ - crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" -#else -#define STARTFILE_SPEC \ - "%{!shared: %{pg|p:gcrt1.o%s;:crt1.o%s}}\ - crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" -#endif - -/* Provide a ENDFILE_SPEC appropriate for ELF. Here we tack on the - magical crtend.o file which provides part of the support for - getting C++ file-scope static object constructed before entering - `main', followed by a normal ELF "finalizer" file, `crtn.o'. */ - -#undef ENDFILE_SPEC -#define ENDFILE_SPEC \ - "%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ - %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s" - -/* We support #pragma. */ -#define HANDLE_SYSV_PRAGMA 1 - -/* Select a format to encode pointers in exception handling data. CODE - is 0 for data, 1 for code labels, 2 for function pointers. GLOBAL is - true if the symbol may be affected by dynamic relocations. - - Since application size is already constrained to <2GB by the form of - the ldgp relocation, we can use a 32-bit pc-relative relocation to - static data. Dynamic data is accessed indirectly to allow for read - only EH sections. */ -#define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL) \ - (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) - -/* If defined, a C statement to be executed just prior to the output of - assembler code for INSN. */ -#define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS) \ - (alpha_this_literal_sequence_number = 0, \ - alpha_this_gpdisp_sequence_number = 0) -extern int alpha_this_literal_sequence_number; -extern int alpha_this_gpdisp_sequence_number; - -/* Since the bits of the _init and _fini function is spread across - many object files, each potentially with its own GP, we must assume - we need to load our GP. Further, the .init/.fini section can - easily be more than 4MB away from the function to call so we can't - use bsr. */ -#define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \ - asm (SECTION_OP "\n" \ -" br $29,1f\n" \ -"1: ldgp $29,0($29)\n" \ -" unop\n" \ -" jsr $26," USER_LABEL_PREFIX #FUNC "\n" \ -" .align 3\n" \ -" .previous"); - -/* If we have the capability create headers for efficient EH lookup. - As of Jan 2002, only glibc 2.2.4 can actually make use of this, but - I imagine that other systems will catch up. In the meantime, it - doesn't harm to make sure that the data exists to be used later. */ -#if defined(HAVE_LD_EH_FRAME_HDR) -#define LINK_EH_SPEC "%{!static:--eh-frame-hdr} " -#endif diff --git a/contrib/gcc/config/alpha/freebsd.h b/contrib/gcc/config/alpha/freebsd.h deleted file mode 100644 index b007989..0000000 --- a/contrib/gcc/config/alpha/freebsd.h +++ /dev/null @@ -1,133 +0,0 @@ -/* Definitions for DEC Alpha/AXP running FreeBSD using the ELF format - Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc. - Contributed by David E. O'Brien <obrien@FreeBSD.org> and BSDi. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -#undef SUBTARGET_EXTRA_SPECS -#define SUBTARGET_EXTRA_SPECS \ - { "fbsd_dynamic_linker", FBSD_DYNAMIC_LINKER } - -/* Provide a FBSD_TARGET_CPU_CPP_BUILTINS and CPP_SPEC appropriate for - FreeBSD/alpha. Besides the dealing with - the GCC option `-posix', and PIC issues as on all FreeBSD platforms, we must - deal with the Alpha's FP issues. */ - -#undef FBSD_TARGET_CPU_CPP_BUILTINS -#define FBSD_TARGET_CPU_CPP_BUILTINS() \ - do \ - { \ - builtin_define ("__LP64__"); \ - if (flag_pic) \ - { \ - builtin_define ("__PIC__"); \ - builtin_define ("__pic__"); \ - } \ - } \ - while (0) - -#undef CPP_SPEC -#define CPP_SPEC "%(cpp_subtarget) %{posix:-D_POSIX_SOURCE}" - -#define LINK_SPEC "%{G*} %{relax:-relax} \ - %{p:%nconsider using `-pg' instead of `-p' with gprof(1)} \ - %{Wl,*:%*} \ - %{assert*} %{R*} %{rpath*} %{defsym*} \ - %{shared:-Bshareable %{h*} %{soname*}} \ - %{!shared: \ - %{!static: \ - %{rdynamic:-export-dynamic} \ - %{!dynamic-linker:-dynamic-linker %(fbsd_dynamic_linker) }} \ - %{static:-Bstatic}} \ - %{symbolic:-Bsymbolic}" - -/* Reset our STARTFILE_SPEC because of a moronic pigheaded - Linuxism(glibc'ism) that was added to alpha/elf.h. */ - -#undef STARTFILE_SPEC -#define STARTFILE_SPEC FBSD_STARTFILE_SPEC - - -/************************[ Target stuff ]***********************************/ - -/* Define the actual types of some ANSI-mandated types. - Needs to agree with <machine/ansi.h>. GCC defaults come from c-decl.c, - c-common.c, and config/<arch>/<arch>.h. */ - -/* alpha.h gets this wrong for FreeBSD. We use the GCC defaults instead. */ -#undef WCHAR_TYPE - -#undef WCHAR_TYPE_SIZE -#define WCHAR_TYPE_SIZE 32 - -/* Handle cross-compilation on 32-bits machines (such as i386) for 64-bits - machines (Alpha in this case). */ - -#if defined(__i386__) -#undef HOST_BITS_PER_LONG -#define HOST_BITS_PER_LONG 32 -#undef HOST_WIDE_INT -#define HOST_WIDE_INT long long -#undef HOST_BITS_PER_WIDE_INT -#define HOST_BITS_PER_WIDE_INT 64 -#endif - -/* This is the pseudo-op used to generate a 64-bit word of data with a - specific value in some section. */ - -#undef TARGET_VERSION -#define TARGET_VERSION fprintf (stderr, " (FreeBSD/Alpha ELF)"); - -#define TARGET_ELF 1 - -#undef OBJECT_FORMAT_COFF -#undef EXTENDED_COFF - -#undef TARGET_DEFAULT -#define TARGET_DEFAULT (MASK_FP | MASK_FPREGS | MASK_GAS) - -#undef HAS_INIT_SECTION - -/* Show that we need a GP when profiling. */ -#undef TARGET_PROFILING_NEEDS_GP -#define TARGET_PROFILING_NEEDS_GP 1 - -/* We always use gas here, so we don't worry about ECOFF assembler problems. */ -#undef TARGET_GAS -#define TARGET_GAS 1 - - -/************************[ Assembler stuff ]********************************/ - - - -/************************[ Debugger stuff ]*********************************/ - -/* This is the char to use for continuation (in case we need to turn - continuation back on). */ - -#undef DBX_CONTIN_CHAR -#define DBX_CONTIN_CHAR '?' - -/* Don't default to pcc-struct-return, we want to retain compatibility with - older FreeBSD releases AND pcc-struct-return may not be reentrant. */ - -#undef DEFAULT_PCC_STRUCT_RETURN -#define DEFAULT_PCC_STRUCT_RETURN 0 diff --git a/contrib/gcc/cppinit.c b/contrib/gcc/cppinit.c deleted file mode 100644 index a713cea..0000000 --- a/contrib/gcc/cppinit.c +++ /dev/null @@ -1,634 +0,0 @@ -/* CPP Library. - Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. - Contributed by Per Bothner, 1994-95. - Based on CCCP program by Paul Rubin, June 1986 - Adapted to ANSI C, Richard Stallman, Jan 1987 - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -#include "config.h" -#include "system.h" -#include "cpplib.h" -#include "cpphash.h" -#include "mkdeps.h" - -static void init_library (void); -static void mark_named_operators (cpp_reader *); -static void read_original_filename (cpp_reader *); -static void read_original_directory (cpp_reader *); -static void post_options (cpp_reader *); - -/* If we have designated initializers (GCC >2.7) these tables can be - initialized, constant data. Otherwise, they have to be filled in at - runtime. */ -#if HAVE_DESIGNATED_INITIALIZERS - -#define init_trigraph_map() /* Nothing. */ -#define TRIGRAPH_MAP \ -__extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { - -#define END }; -#define s(p, v) [p] = v, - -#else - -#define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \ - static void init_trigraph_map (void) { \ - unsigned char *x = _cpp_trigraph_map; - -#define END } -#define s(p, v) x[p] = v; - -#endif - -TRIGRAPH_MAP - s('=', '#') s(')', ']') s('!', '|') - s('(', '[') s('\'', '^') s('>', '}') - s('/', '\\') s('<', '{') s('-', '~') -END - -#undef s -#undef END -#undef TRIGRAPH_MAP - -/* A set of booleans indicating what CPP features each source language - requires. */ -struct lang_flags -{ - char c99; - char cplusplus; - char extended_numbers; - char std; - char cplusplus_comments; - char digraphs; -}; - -static const struct lang_flags lang_defaults[] = -{ /* c99 c++ xnum std // digr */ - /* GNUC89 */ { 0, 0, 1, 0, 1, 1 }, - /* GNUC99 */ { 1, 0, 1, 0, 1, 1 }, - /* STDC89 */ { 0, 0, 0, 1, 0, 0 }, - /* STDC94 */ { 0, 0, 0, 1, 0, 1 }, - /* STDC99 */ { 1, 0, 1, 1, 1, 1 }, - /* GNUCXX */ { 0, 1, 1, 0, 1, 1 }, - /* CXX98 */ { 0, 1, 1, 1, 1, 1 }, - /* ASM */ { 0, 0, 1, 0, 1, 0 } -}; - -/* Sets internal flags correctly for a given language. */ -void -cpp_set_lang (cpp_reader *pfile, enum c_lang lang) -{ - const struct lang_flags *l = &lang_defaults[(int) lang]; - - CPP_OPTION (pfile, lang) = lang; - - CPP_OPTION (pfile, c99) = l->c99; - CPP_OPTION (pfile, cplusplus) = l->cplusplus; - CPP_OPTION (pfile, extended_numbers) = l->extended_numbers; - CPP_OPTION (pfile, std) = l->std; - CPP_OPTION (pfile, trigraphs) = l->std; - CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments; - CPP_OPTION (pfile, digraphs) = l->digraphs; -} - -/* Initialize library global state. */ -static void -init_library (void) -{ - static int initialized = 0; - - if (! initialized) - { - initialized = 1; - - /* Set up the trigraph map. This doesn't need to do anything if - we were compiled with a compiler that supports C99 designated - initializers. */ - init_trigraph_map (); - } -} - -/* Initialize a cpp_reader structure. */ -cpp_reader * -cpp_create_reader (enum c_lang lang, hash_table *table) -{ - cpp_reader *pfile; - - /* Initialize this instance of the library if it hasn't been already. */ - init_library (); - - pfile = xcalloc (1, sizeof (cpp_reader)); - - cpp_set_lang (pfile, lang); - CPP_OPTION (pfile, warn_multichar) = 1; - CPP_OPTION (pfile, discard_comments) = 1; - CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1; - CPP_OPTION (pfile, show_column) = 1; - CPP_OPTION (pfile, tabstop) = 8; - CPP_OPTION (pfile, operator_names) = 1; - CPP_OPTION (pfile, warn_trigraphs) = 2; - CPP_OPTION (pfile, warn_endif_labels) = 1; - CPP_OPTION (pfile, warn_deprecated) = 1; - CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); - CPP_OPTION (pfile, dollars_in_ident) = 1; - CPP_OPTION (pfile, warn_dollars) = 1; - - /* Default CPP arithmetic to something sensible for the host for the - benefit of dumb users like fix-header. */ - CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long); - CPP_OPTION (pfile, char_precision) = CHAR_BIT; - CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int); - CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int); - CPP_OPTION (pfile, unsigned_char) = 0; - CPP_OPTION (pfile, unsigned_wchar) = 1; - CPP_OPTION (pfile, bytes_big_endian) = 1; /* does not matter */ - - /* Default to locale/UTF-8. */ - CPP_OPTION (pfile, narrow_charset) = _cpp_default_encoding (); - CPP_OPTION (pfile, wide_charset) = 0; - CPP_OPTION (pfile, input_charset) = _cpp_default_encoding (); - - /* A fake empty "directory" used as the starting point for files - looked up without a search path. Name cannot be '/' because we - don't want to prepend anything at all to filenames using it. All - other entries are correct zero-initialized. */ - pfile->no_search_path.name = (char *) ""; - - /* Initialize the line map. Start at logical line 1, so we can use - a line number of zero for special states. */ - linemap_init (&pfile->line_maps); - pfile->line = 1; - - /* Initialize lexer state. */ - pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); - - /* Set up static tokens. */ - pfile->avoid_paste.type = CPP_PADDING; - pfile->avoid_paste.val.source = NULL; - pfile->eof.type = CPP_EOF; - pfile->eof.flags = 0; - - /* Create a token buffer for the lexer. */ - _cpp_init_tokenrun (&pfile->base_run, 250); - pfile->cur_run = &pfile->base_run; - pfile->cur_token = pfile->base_run.base; - - /* Initialize the base context. */ - pfile->context = &pfile->base_context; - pfile->base_context.macro = 0; - pfile->base_context.prev = pfile->base_context.next = 0; - - /* Aligned and unaligned storage. */ - pfile->a_buff = _cpp_get_buff (pfile, 0); - pfile->u_buff = _cpp_get_buff (pfile, 0); - - /* The expression parser stack. */ - _cpp_expand_op_stack (pfile); - - /* Initialize the buffer obstack. */ - _obstack_begin (&pfile->buffer_ob, 0, 0, - (void *(*) (long)) xmalloc, - (void (*) (void *)) free); - - _cpp_init_files (pfile); - - _cpp_init_hashtable (pfile, table); - - return pfile; -} - -/* Free resources used by PFILE. Accessing PFILE after this function - returns leads to undefined behavior. Returns the error count. */ -void -cpp_destroy (cpp_reader *pfile) -{ - cpp_context *context, *contextn; - tokenrun *run, *runn; - - free (pfile->op_stack); - - while (CPP_BUFFER (pfile) != NULL) - _cpp_pop_buffer (pfile); - - if (pfile->out.base) - free (pfile->out.base); - - if (pfile->macro_buffer) - { - free (pfile->macro_buffer); - pfile->macro_buffer = NULL; - pfile->macro_buffer_len = 0; - } - - if (pfile->deps) - deps_free (pfile->deps); - obstack_free (&pfile->buffer_ob, 0); - - _cpp_destroy_hashtable (pfile); - _cpp_cleanup_files (pfile); - _cpp_destroy_iconv (pfile); - - _cpp_free_buff (pfile->a_buff); - _cpp_free_buff (pfile->u_buff); - _cpp_free_buff (pfile->free_buffs); - - for (run = &pfile->base_run; run; run = runn) - { - runn = run->next; - free (run->base); - if (run != &pfile->base_run) - free (run); - } - - for (context = pfile->base_context.next; context; context = contextn) - { - contextn = context->next; - free (context); - } - - linemap_free (&pfile->line_maps); - free (pfile); -} - -/* This structure defines one built-in identifier. A node will be - entered in the hash table under the name NAME, with value VALUE. - - There are two tables of these. builtin_array holds all the - "builtin" macros: these are handled by builtin_macro() in - cppmacro.c. Builtin is somewhat of a misnomer -- the property of - interest is that these macros require special code to compute their - expansions. The value is a "builtin_type" enumerator. - - operator_array holds the C++ named operators. These are keywords - which act as aliases for punctuators. In C++, they cannot be - altered through #define, and #if recognizes them as operators. In - C, these are not entered into the hash table at all (but see - <iso646.h>). The value is a token-type enumerator. */ -struct builtin -{ - const uchar *name; - unsigned short len; - unsigned short value; -}; - -#define B(n, t) { DSC(n), t } -static const struct builtin builtin_array[] = -{ - B("__TIME__", BT_TIME), - B("__DATE__", BT_DATE), - B("__FILE__", BT_FILE), - B("__BASE_FILE__", BT_BASE_FILE), - B("__LINE__", BT_SPECLINE), - B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL), - /* Keep builtins not used for -traditional-cpp at the end, and - update init_builtins() if any more are added. */ - B("_Pragma", BT_PRAGMA), - B("__STDC__", BT_STDC), -}; - -static const struct builtin operator_array[] = -{ - B("and", CPP_AND_AND), - B("and_eq", CPP_AND_EQ), - B("bitand", CPP_AND), - B("bitor", CPP_OR), - B("compl", CPP_COMPL), - B("not", CPP_NOT), - B("not_eq", CPP_NOT_EQ), - B("or", CPP_OR_OR), - B("or_eq", CPP_OR_EQ), - B("xor", CPP_XOR), - B("xor_eq", CPP_XOR_EQ) -}; -#undef B - -/* Mark the C++ named operators in the hash table. */ -static void -mark_named_operators (cpp_reader *pfile) -{ - const struct builtin *b; - - for (b = operator_array; - b < (operator_array + ARRAY_SIZE (operator_array)); - b++) - { - cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); - hp->flags |= NODE_OPERATOR; - hp->is_directive = 0; - hp->directive_index = b->value; - } -} - -/* Read the builtins table above and enter them, and language-specific - macros, into the hash table. HOSTED is true if this is a hosted - environment. */ -void -cpp_init_builtins (cpp_reader *pfile, int hosted) -{ - const struct builtin *b; - size_t n = ARRAY_SIZE (builtin_array); - - if (CPP_OPTION (pfile, traditional)) - n -= 2; - - for(b = builtin_array; b < builtin_array + n; b++) - { - cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); - hp->type = NT_MACRO; - hp->flags |= NODE_BUILTIN | NODE_WARN; - hp->value.builtin = b->value; - } - - if (CPP_OPTION (pfile, cplusplus)) - _cpp_define_builtin (pfile, "__cplusplus 1"); - else if (CPP_OPTION (pfile, lang) == CLK_ASM) - _cpp_define_builtin (pfile, "__ASSEMBLER__ 1"); - else if (CPP_OPTION (pfile, lang) == CLK_STDC94) - _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L"); - else if (CPP_OPTION (pfile, c99)) - _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L"); - - if (hosted) - _cpp_define_builtin (pfile, "__STDC_HOSTED__ 1"); - else - _cpp_define_builtin (pfile, "__STDC_HOSTED__ 0"); - - if (CPP_OPTION (pfile, objc)) - _cpp_define_builtin (pfile, "__OBJC__ 1"); -} - -/* Sanity-checks are dependent on command-line options, so it is - called as a subroutine of cpp_read_main_file (). */ -#if ENABLE_CHECKING -static void sanity_checks (cpp_reader *); -static void sanity_checks (cpp_reader *pfile) -{ - cppchar_t test = 0; - size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part); - - /* Sanity checks for assumptions about CPP arithmetic and target - type precisions made by cpplib. */ - test--; - if (test < 1) - cpp_error (pfile, CPP_DL_ICE, "cppchar_t must be an unsigned type"); - - if (CPP_OPTION (pfile, precision) > max_precision) - cpp_error (pfile, CPP_DL_ICE, - "preprocessor arithmetic has maximum precision of %lu bits;" - " target requires %lu bits", - (unsigned long) max_precision, - (unsigned long) CPP_OPTION (pfile, precision)); - - if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision)) - cpp_error (pfile, CPP_DL_ICE, - "CPP arithmetic must be at least as precise as a target int"); - - if (CPP_OPTION (pfile, char_precision) < 8) - cpp_error (pfile, CPP_DL_ICE, "target char is less than 8 bits wide"); - - if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision)) - cpp_error (pfile, CPP_DL_ICE, - "target wchar_t is narrower than target char"); - - if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision)) - cpp_error (pfile, CPP_DL_ICE, - "target int is narrower than target char"); - - /* This is assumed in eval_token() and could be fixed if necessary. */ - if (sizeof (cppchar_t) > sizeof (cpp_num_part)) - cpp_error (pfile, CPP_DL_ICE, - "CPP half-integer narrower than CPP character"); - - if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T) - cpp_error (pfile, CPP_DL_ICE, - "CPP on this host cannot handle wide character constants over" - " %lu bits, but the target requires %lu bits", - (unsigned long) BITS_PER_CPPCHAR_T, - (unsigned long) CPP_OPTION (pfile, wchar_precision)); -} -#else -# define sanity_checks(PFILE) -#endif - -/* Add a dependency target. Can be called any number of times before - cpp_read_main_file(). If no targets have been added before - cpp_read_main_file(), then the default target is used. */ -void -cpp_add_dependency_target (cpp_reader *pfile, const char *target, int quote) -{ - if (!pfile->deps) - pfile->deps = deps_init (); - - deps_add_target (pfile->deps, target, quote); -} - -/* This is called after options have been parsed, and partially - processed. */ -void -cpp_post_options (cpp_reader *pfile) -{ - sanity_checks (pfile); - - post_options (pfile); - - /* Mark named operators before handling command line macros. */ - if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names)) - mark_named_operators (pfile); -} - -/* Setup for processing input from the file named FNAME, or stdin if - it is the empty string. Return the original filename - on success (e.g. foo.i->foo.c), or NULL on failure. */ -const char * -cpp_read_main_file (cpp_reader *pfile, const char *fname) -{ - if (CPP_OPTION (pfile, deps.style) != DEPS_NONE) - { - if (!pfile->deps) - pfile->deps = deps_init (); - - /* Set the default target (if there is none already). */ - deps_add_default_target (pfile->deps, fname); - } - - pfile->main_file - = _cpp_find_file (pfile, fname, &pfile->no_search_path, false, 0); - if (_cpp_find_failed (pfile->main_file)) - return NULL; - - _cpp_stack_file (pfile, pfile->main_file, false); - - /* For foo.i, read the original filename foo.c now, for the benefit - of the front ends. */ - if (CPP_OPTION (pfile, preprocessed)) - { - read_original_filename (pfile); - if (!pfile->map) - return NULL; - fname = pfile->map->to_file; - } - return fname; -} - -/* For preprocessed files, if the first tokens are of the form # NUM. - handle the directive so we know the original file name. This will - generate file_change callbacks, which the front ends must handle - appropriately given their state of initialization. */ -static void -read_original_filename (cpp_reader *pfile) -{ - const cpp_token *token, *token1; - - /* Lex ahead; if the first tokens are of the form # NUM, then - process the directive, otherwise back up. */ - token = _cpp_lex_direct (pfile); - if (token->type == CPP_HASH) - { - pfile->state.in_directive = 1; - token1 = _cpp_lex_direct (pfile); - _cpp_backup_tokens (pfile, 1); - pfile->state.in_directive = 0; - - /* If it's a #line directive, handle it. */ - if (token1->type == CPP_NUMBER) - { - _cpp_handle_directive (pfile, token->flags & PREV_WHITE); - read_original_directory (pfile); - return; - } - } - - /* Backup as if nothing happened. */ - _cpp_backup_tokens (pfile, 1); -} - -/* For preprocessed files, if the tokens following the first filename - line is of the form # <line> "/path/name//", handle the - directive so we know the original current directory. */ -static void -read_original_directory (cpp_reader *pfile) -{ - const cpp_token *hash, *token; - - /* Lex ahead; if the first tokens are of the form # NUM, then - process the directive, otherwise back up. */ - hash = _cpp_lex_direct (pfile); - if (hash->type != CPP_HASH) - { - _cpp_backup_tokens (pfile, 1); - return; - } - - token = _cpp_lex_direct (pfile); - - if (token->type != CPP_NUMBER) - { - _cpp_backup_tokens (pfile, 2); - return; - } - - token = _cpp_lex_direct (pfile); - - if (token->type != CPP_STRING - || ! (token->val.str.len >= 5 - && token->val.str.text[token->val.str.len-2] == '/' - && token->val.str.text[token->val.str.len-3] == '/')) - { - _cpp_backup_tokens (pfile, 3); - return; - } - - if (pfile->cb.dir_change) - { - char *debugdir = alloca (token->val.str.len - 3); - - memcpy (debugdir, (const char *) token->val.str.text + 1, - token->val.str.len - 4); - debugdir[token->val.str.len - 4] = '\0'; - - pfile->cb.dir_change (pfile, debugdir); - } -} - -/* This is called at the end of preprocessing. It pops the last - buffer and writes dependency output, and returns the number of - errors. - - Maybe it should also reset state, such that you could call - cpp_start_read with a new filename to restart processing. */ -int -cpp_finish (cpp_reader *pfile, FILE *deps_stream) -{ - /* Warn about unused macros before popping the final buffer. */ - if (CPP_OPTION (pfile, warn_unused_macros)) - cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL); - - /* cpplex.c leaves the final buffer on the stack. This it so that - it returns an unending stream of CPP_EOFs to the client. If we - popped the buffer, we'd dereference a NULL buffer pointer and - segfault. It's nice to allow the client to do worry-free excess - cpp_get_token calls. */ - while (pfile->buffer) - _cpp_pop_buffer (pfile); - - /* Don't write the deps file if there are errors. */ - if (CPP_OPTION (pfile, deps.style) != DEPS_NONE - && deps_stream && pfile->errors == 0) - { - deps_write (pfile->deps, deps_stream, 72); - - if (CPP_OPTION (pfile, deps.phony_targets)) - deps_phony_targets (pfile->deps, deps_stream); - } - - /* Report on headers that could use multiple include guards. */ - if (CPP_OPTION (pfile, print_include_names)) - _cpp_report_missing_guards (pfile); - - return pfile->errors; -} - -static void -post_options (cpp_reader *pfile) -{ - /* -Wtraditional is not useful in C++ mode. */ - if (CPP_OPTION (pfile, cplusplus)) - CPP_OPTION (pfile, warn_traditional) = 0; - - /* Permanently disable macro expansion if we are rescanning - preprocessed text. Read preprocesed source in ISO mode. */ - if (CPP_OPTION (pfile, preprocessed)) - { - pfile->state.prevent_expansion = 1; - CPP_OPTION (pfile, traditional) = 0; - } - - if (CPP_OPTION (pfile, warn_trigraphs) == 2) - CPP_OPTION (pfile, warn_trigraphs) = !CPP_OPTION (pfile, trigraphs); - - if (CPP_OPTION (pfile, traditional)) - { - CPP_OPTION (pfile, cplusplus_comments) = 0; - - /* Traditional CPP does not accurately track column information. */ - CPP_OPTION (pfile, show_column) = 0; - CPP_OPTION (pfile, trigraphs) = 0; - CPP_OPTION (pfile, warn_trigraphs) = 0; - } -} diff --git a/contrib/gcc/dwarfout.c b/contrib/gcc/dwarfout.c deleted file mode 100644 index bbbfcfc..0000000 --- a/contrib/gcc/dwarfout.c +++ /dev/null @@ -1,6561 +0,0 @@ -/* Output Dwarf format symbol table information from the GNU C compiler. - Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 2002, - 1999, 2000, 2001, 2002 Free Software Foundation, Inc. - Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later -version. - -GCC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. */ - -/* - - Notes on the GNU Implementation of DWARF Debugging Information - -------------------------------------------------------------- - Last Major Update: Sun Jul 17 08:17:42 PDT 1994 by rfg@segfault.us.com - ------------------------------------------------------------ - - This file describes special and unique aspects of the GNU implementation of - the DWARF Version 1 debugging information language, as provided in the GNU - version 2.x compiler(s). - - For general information about the DWARF debugging information language, - you should obtain the DWARF version 1.1 specification document (and perhaps - also the DWARF version 2 draft specification document) developed by the - (now defunct) UNIX International Programming Languages Special Interest Group. - - To obtain a copy of the DWARF Version 1 and/or DWARF Version 2 - specification, visit the web page for the DWARF Version 2 committee, at - - http://www.eagercon.com/dwarf/dwarf2std.htm - - The generation of DWARF debugging information by the GNU version 2.x C - compiler has now been tested rather extensively for m88k, i386, i860, and - SPARC targets. The DWARF output of the GNU C compiler appears to inter- - operate well with the standard SVR4 SDB debugger on these kinds of target - systems (but of course, there are no guarantees). - - DWARF 1 generation for the GNU g++ compiler is implemented, but limited. - C++ users should definitely use DWARF 2 instead. - - Future plans for the dwarfout.c module of the GNU compiler(s) includes the - addition of full support for GNU FORTRAN. (This should, in theory, be a - lot simpler to add than adding support for g++... but we'll see.) - - Many features of the DWARF version 2 specification have been adapted to - (and used in) the GNU implementation of DWARF (version 1). In most of - these cases, a DWARF version 2 approach is used in place of (or in addition - to) DWARF version 1 stuff simply because it is apparent that DWARF version - 1 is not sufficiently expressive to provide the kinds of information which - may be necessary to support really robust debugging. In all of these cases - however, the use of DWARF version 2 features should not interfere in any - way with the interoperability (of GNU compilers) with generally available - "classic" (pre version 1) DWARF consumer tools (e.g. SVR4 SDB). - - The DWARF generation enhancement for the GNU compiler(s) was initially - donated to the Free Software Foundation by Network Computing Devices. - (Thanks NCD!) Additional development and maintenance of dwarfout.c has - been largely supported (i.e. funded) by Intel Corporation. (Thanks Intel!) - - If you have questions or comments about the DWARF generation feature, please - send mail to me <rfg@netcom.com>. I will be happy to investigate any bugs - reported and I may even provide fixes (but of course, I can make no promises). - - The DWARF debugging information produced by GCC may deviate in a few minor - (but perhaps significant) respects from the DWARF debugging information - currently produced by other C compilers. A serious attempt has been made - however to conform to the published specifications, to existing practice, - and to generally accepted norms in the GNU implementation of DWARF. - - ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** - - Under normal circumstances, the DWARF information generated by the GNU - compilers (in an assembly language file) is essentially impossible for - a human being to read. This fact can make it very difficult to debug - certain DWARF-related problems. In order to overcome this difficulty, - a feature has been added to dwarfout.c (enabled by the -dA - option) which causes additional comments to be placed into the assembly - language output file, out to the right-hand side of most bits of DWARF - material. The comments indicate (far more clearly that the obscure - DWARF hex codes do) what is actually being encoded in DWARF. Thus, the - -dA option can be highly useful for those who must study the - DWARF output from the GNU compilers in detail. - - --------- - - (Footnote: Within this file, the term `Debugging Information Entry' will - be abbreviated as `DIE'.) - - - Release Notes (aka known bugs) - ------------------------------- - - In one very obscure case involving dynamically sized arrays, the DWARF - "location information" for such an array may make it appear that the - array has been totally optimized out of existence, when in fact it - *must* actually exist. (This only happens when you are using *both* -g - *and* -O.) This is due to aggressive dead store elimination in the - compiler, and to the fact that the DECL_RTL expressions associated with - variables are not always updated to correctly reflect the effects of - GCC's aggressive dead store elimination. - - ------------------------------- - - When attempting to set a breakpoint at the "start" of a function compiled - with -g1, the debugger currently has no way of knowing exactly where the - end of the prologue code for the function is. Thus, for most targets, - all the debugger can do is to set the breakpoint at the AT_low_pc address - for the function. But if you stop there and then try to look at one or - more of the formal parameter values, they may not have been "homed" yet, - so you may get inaccurate answers (or perhaps even addressing errors). - - Some people may consider this simply a non-feature, but I consider it a - bug, and I hope to provide some GNU-specific attributes (on function - DIEs) which will specify the address of the end of the prologue and the - address of the beginning of the epilogue in a future release. - - ------------------------------- - - It is believed at this time that old bugs relating to the AT_bit_offset - values for bit-fields have been fixed. - - There may still be some very obscure bugs relating to the DWARF description - of type `long long' bit-fields for target machines (e.g. 80x86 machines) - where the alignment of type `long long' data objects is different from - (and less than) the size of a type `long long' data object. - - Please report any problems with the DWARF description of bit-fields as you - would any other GCC bug. (Procedures for bug reporting are given in the - GNU C compiler manual.) - - -------------------------------- - - At this time, GCC does not know how to handle the GNU C "nested functions" - extension. (See the GCC manual for more info on this extension to ANSI C.) - - -------------------------------- - - The GNU compilers now represent inline functions (and inlined instances - thereof) in exactly the manner described by the current DWARF version 2 - (draft) specification. The version 1 specification for handling inline - functions (and inlined instances) was known to be brain-damaged (by the - PLSIG) when the version 1 spec was finalized, but it was simply too late - in the cycle to get it removed before the version 1 spec was formally - released to the public (by UI). - - -------------------------------- - - At this time, GCC does not generate the kind of really precise information - about the exact declared types of entities with signed integral types which - is required by the current DWARF draft specification. - - Specifically, the current DWARF draft specification seems to require that - the type of a non-unsigned integral bit-field member of a struct or union - type be represented as either a "signed" type or as a "plain" type, - depending upon the exact set of keywords that were used in the - type specification for the given bit-field member. It was felt (by the - UI/PLSIG) that this distinction between "plain" and "signed" integral types - could have some significance (in the case of bit-fields) because ANSI C - does not constrain the signedness of a plain bit-field, whereas it does - constrain the signedness of an explicitly "signed" bit-field. For this - reason, the current DWARF specification calls for compilers to produce - type information (for *all* integral typed entities... not just bit-fields) - which explicitly indicates the signedness of the relevant type to be - "signed" or "plain" or "unsigned". - - Unfortunately, the GNU DWARF implementation is currently incapable of making - such distinctions. - - -------------------------------- - - - Known Interoperability Problems - ------------------------------- - - Although the GNU implementation of DWARF conforms (for the most part) with - the current UI/PLSIG DWARF version 1 specification (with many compatible - version 2 features added in as "vendor specific extensions" just for good - measure) there are a few known cases where GCC's DWARF output can cause - some confusion for "classic" (pre version 1) DWARF consumers such as the - System V Release 4 SDB debugger. These cases are described in this section. - - -------------------------------- - - The DWARF version 1 specification includes the fundamental type codes - FT_ext_prec_float, FT_complex, FT_dbl_prec_complex, and FT_ext_prec_complex. - Since GNU C is only a C compiler (and since C doesn't provide any "complex" - data types) the only one of these fundamental type codes which GCC ever - generates is FT_ext_prec_float. This fundamental type code is generated - by GCC for the `long double' data type. Unfortunately, due to an apparent - bug in the SVR4 SDB debugger, SDB can become very confused wherever any - attempt is made to print a variable, parameter, or field whose type was - given in terms of FT_ext_prec_float. - - (Actually, SVR4 SDB fails to understand *any* of the four fundamental type - codes mentioned here. This will fact will cause additional problems when - there is a GNU FORTRAN front-end.) - - -------------------------------- - - In general, it appears that SVR4 SDB is not able to effectively ignore - fundamental type codes in the "implementation defined" range. This can - cause problems when a program being debugged uses the `long long' data - type (or the signed or unsigned varieties thereof) because these types - are not defined by ANSI C, and thus, GCC must use its own private fundamental - type codes (from the implementation-defined range) to represent these types. - - -------------------------------- - - - General GNU DWARF extensions - ---------------------------- - - In the current DWARF version 1 specification, no mechanism is specified by - which accurate information about executable code from include files can be - properly (and fully) described. (The DWARF version 2 specification *does* - specify such a mechanism, but it is about 10 times more complicated than - it needs to be so I'm not terribly anxious to try to implement it right - away.) - - In the GNU implementation of DWARF version 1, a fully downward-compatible - extension has been implemented which permits the GNU compilers to specify - which executable lines come from which files. This extension places - additional information (about source file names) in GNU-specific sections - (which should be totally ignored by all non-GNU DWARF consumers) so that - this extended information can be provided (to GNU DWARF consumers) in a way - which is totally transparent (and invisible) to non-GNU DWARF consumers - (e.g. the SVR4 SDB debugger). The additional information is placed *only* - in specialized GNU-specific sections, where it should never even be seen - by non-GNU DWARF consumers. - - To understand this GNU DWARF extension, imagine that the sequence of entries - in the .lines section is broken up into several subsections. Each contiguous - sequence of .line entries which relates to a sequence of lines (or statements) - from one particular file (either a `base' file or an `include' file) could - be called a `line entries chunk' (LEC). - - For each LEC there is one entry in the .debug_srcinfo section. - - Each normal entry in the .debug_srcinfo section consists of two 4-byte - words of data as follows: - - (1) The starting address (relative to the entire .line section) - of the first .line entry in the relevant LEC. - - (2) The starting address (relative to the entire .debug_sfnames - section) of a NUL terminated string representing the - relevant filename. (This filename name be either a - relative or an absolute filename, depending upon how the - given source file was located during compilation.) - - Obviously, each .debug_srcinfo entry allows you to find the relevant filename, - and it also points you to the first .line entry that was generated as a result - of having compiled a given source line from the given source file. - - Each subsequent .line entry should also be assumed to have been produced - as a result of compiling yet more lines from the same file. The end of - any given LEC is easily found by looking at the first 4-byte pointer in - the *next* .debug_srcinfo entry. That next .debug_srcinfo entry points - to a new and different LEC, so the preceding LEC (implicitly) must have - ended with the last .line section entry which occurs at the 2 1/2 words - just before the address given in the first pointer of the new .debug_srcinfo - entry. - - The following picture may help to clarify this feature. Let's assume that - `LE' stands for `.line entry'. Also, assume that `* 'stands for a pointer. - - - .line section .debug_srcinfo section .debug_sfnames section - ---------------------------------------------------------------- - - LE <---------------------- * - LE * -----------------> "foobar.c" <--- - LE | - LE | - LE <---------------------- * | - LE * -----------------> "foobar.h" <| | - LE | | - LE | | - LE <---------------------- * | | - LE * -----------------> "inner.h" | | - LE | | - LE <---------------------- * | | - LE * ------------------------------- | - LE | - LE | - LE | - LE | - LE <---------------------- * | - LE * ----------------------------------- - LE - LE - LE - - In effect, each entry in the .debug_srcinfo section points to *both* a - filename (in the .debug_sfnames section) and to the start of a block of - consecutive LEs (in the .line section). - - Note that just like in the .line section, there are specialized first and - last entries in the .debug_srcinfo section for each object file. These - special first and last entries for the .debug_srcinfo section are very - different from the normal .debug_srcinfo section entries. They provide - additional information which may be helpful to a debugger when it is - interpreting the data in the .debug_srcinfo, .debug_sfnames, and .line - sections. - - The first entry in the .debug_srcinfo section for each compilation unit - consists of five 4-byte words of data. The contents of these five words - should be interpreted (by debuggers) as follows: - - (1) The starting address (relative to the entire .line section) - of the .line section for this compilation unit. - - (2) The starting address (relative to the entire .debug_sfnames - section) of the .debug_sfnames section for this compilation - unit. - - (3) The starting address (in the execution virtual address space) - of the .text section for this compilation unit. - - (4) The ending address plus one (in the execution virtual address - space) of the .text section for this compilation unit. - - (5) The date/time (in seconds since midnight 1/1/70) at which the - compilation of this compilation unit occurred. This value - should be interpreted as an unsigned quantity because gcc - might be configured to generate a default value of 0xffffffff - in this field (in cases where it is desired to have object - files created at different times from identical source files - be byte-for-byte identical). By default, these timestamps - are *not* generated by dwarfout.c (so that object files - compiled at different times will be byte-for-byte identical). - If you wish to enable this "timestamp" feature however, you - can simply place a #define for the symbol `DWARF_TIMESTAMPS' - in your target configuration file and then rebuild the GNU - compiler(s). - - Note that the first string placed into the .debug_sfnames section for each - compilation unit is the name of the directory in which compilation occurred. - This string ends with a `/' (to help indicate that it is the pathname of a - directory). Thus, the second word of each specialized initial .debug_srcinfo - entry for each compilation unit may be used as a pointer to the (string) - name of the compilation directory, and that string may in turn be used to - "absolutize" any relative pathnames which may appear later on in the - .debug_sfnames section entries for the same compilation unit. - - The fifth and last word of each specialized starting entry for a compilation - unit in the .debug_srcinfo section may (depending upon your configuration) - indicate the date/time of compilation, and this may be used (by a debugger) - to determine if any of the source files which contributed code to this - compilation unit are newer than the object code for the compilation unit - itself. If so, the debugger may wish to print an "out-of-date" warning - about the compilation unit. - - The .debug_srcinfo section associated with each compilation will also have - a specialized terminating entry. This terminating .debug_srcinfo section - entry will consist of the following two 4-byte words of data: - - (1) The offset, measured from the start of the .line section to - the beginning of the terminating entry for the .line section. - - (2) A word containing the value 0xffffffff. - - -------------------------------- - - In the current DWARF version 1 specification, no mechanism is specified by - which information about macro definitions and un-definitions may be provided - to the DWARF consumer. - - The DWARF version 2 (draft) specification does specify such a mechanism. - That specification was based on the GNU ("vendor specific extension") - which provided some support for macro definitions and un-definitions, - but the "official" DWARF version 2 (draft) specification mechanism for - handling macros and the GNU implementation have diverged somewhat. I - plan to update the GNU implementation to conform to the "official" - DWARF version 2 (draft) specification as soon as I get time to do that. - - Note that in the GNU implementation, additional information about macro - definitions and un-definitions is *only* provided when the -g3 level of - debug-info production is selected. (The default level is -g2 and the - plain old -g option is considered to be identical to -g2.) - - GCC records information about macro definitions and undefinitions primarily - in a section called the .debug_macinfo section. Normal entries in the - .debug_macinfo section consist of the following three parts: - - (1) A special "type" byte. - - (2) A 3-byte line-number/filename-offset field. - - (3) A NUL terminated string. - - The interpretation of the second and third parts is dependent upon the - value of the leading (type) byte. - - The type byte may have one of four values depending upon the type of the - .debug_macinfo entry which follows. The 1-byte MACINFO type codes presently - used, and their meanings are as follows: - - MACINFO_start A base file or an include file starts here. - MACINFO_resume The current base or include file ends here. - MACINFO_define A #define directive occurs here. - MACINFO_undef A #undef directive occur here. - - (Note that the MACINFO_... codes mentioned here are simply symbolic names - for constants which are defined in the GNU dwarf.h file.) - - For MACINFO_define and MACINFO_undef entries, the second (3-byte) field - contains the number of the source line (relative to the start of the current - base source file or the current include files) when the #define or #undef - directive appears. For a MACINFO_define entry, the following string field - contains the name of the macro which is defined, followed by its definition. - Note that the definition is always separated from the name of the macro - by at least one whitespace character. For a MACINFO_undef entry, the - string which follows the 3-byte line number field contains just the name - of the macro which is being undef'ed. - - For a MACINFO_start entry, the 3-byte field following the type byte contains - the offset, relative to the start of the .debug_sfnames section for the - current compilation unit, of a string which names the new source file which - is beginning its inclusion at this point. Following that 3-byte field, - each MACINFO_start entry always contains a zero length NUL terminated - string. - - For a MACINFO_resume entry, the 3-byte field following the type byte contains - the line number WITHIN THE INCLUDING FILE at which the inclusion of the - current file (whose inclusion ends here) was initiated. Following that - 3-byte field, each MACINFO_resume entry always contains a zero length NUL - terminated string. - - Each set of .debug_macinfo entries for each compilation unit is terminated - by a special .debug_macinfo entry consisting of a 4-byte zero value followed - by a single NUL byte. - - -------------------------------- - - In the current DWARF draft specification, no provision is made for providing - a separate level of (limited) debugging information necessary to support - tracebacks (only) through fully-debugged code (e.g. code in system libraries). - - A proposal to define such a level was submitted (by me) to the UI/PLSIG. - This proposal was rejected by the UI/PLSIG for inclusion into the DWARF - version 1 specification for two reasons. First, it was felt (by the PLSIG) - that the issues involved in supporting a "traceback only" subset of DWARF - were not well understood. Second, and perhaps more importantly, the PLSIG - is already having enough trouble agreeing on what it means to be "conforming" - to the DWARF specification, and it was felt that trying to specify multiple - different *levels* of conformance would only complicate our discussions of - this already divisive issue. Nonetheless, the GNU implementation of DWARF - provides an abbreviated "traceback only" level of debug-info production for - use with fully-debugged "system library" code. This level should only be - used for fully debugged system library code, and even then, it should only - be used where there is a very strong need to conserve disk space. This - abbreviated level of debug-info production can be used by specifying the - -g1 option on the compilation command line. - - -------------------------------- - - As mentioned above, the GNU implementation of DWARF currently uses the DWARF - version 2 (draft) approach for inline functions (and inlined instances - thereof). This is used in preference to the version 1 approach because - (quite simply) the version 1 approach is highly brain-damaged and probably - unworkable. - - -------------------------------- - - - GNU DWARF Representation of GNU C Extensions to ANSI C - ------------------------------------------------------ - - The file dwarfout.c has been designed and implemented so as to provide - some reasonable DWARF representation for each and every declarative - construct which is accepted by the GNU C compiler. Since the GNU C - compiler accepts a superset of ANSI C, this means that there are some - cases in which the DWARF information produced by GCC must take some - liberties in improvising DWARF representations for declarations which - are only valid in (extended) GNU C. - - In particular, GNU C provides at least three significant extensions to - ANSI C when it comes to declarations. These are (1) inline functions, - and (2) dynamic arrays, and (3) incomplete enum types. (See the GCC - manual for more information on these GNU extensions to ANSI C.) When - used, these GNU C extensions are represented (in the generated DWARF - output of GCC) in the most natural and intuitively obvious ways. - - In the case of inline functions, the DWARF representation is exactly as - called for in the DWARF version 2 (draft) specification for an identical - function written in C++; i.e. we "reuse" the representation of inline - functions which has been defined for C++ to support this GNU C extension. - - In the case of dynamic arrays, we use the most obvious representational - mechanism available; i.e. an array type in which the upper bound of - some dimension (usually the first and only dimension) is a variable - rather than a constant. (See the DWARF version 1 specification for more - details.) - - In the case of incomplete enum types, such types are represented simply - as TAG_enumeration_type DIEs which DO NOT contain either AT_byte_size - attributes or AT_element_list attributes. - - -------------------------------- - - - Future Directions - ----------------- - - The codes, formats, and other paraphernalia necessary to provide proper - support for symbolic debugging for the C++ language are still being worked - on by the UI/PLSIG. The vast majority of the additions to DWARF which will - be needed to completely support C++ have already been hashed out and agreed - upon, but a few small issues (e.g. anonymous unions, access declarations) - are still being discussed. Also, we in the PLSIG are still discussing - whether or not we need to do anything special for C++ templates. (At this - time it is not yet clear whether we even need to do anything special for - these.) - - With regard to FORTRAN, the UI/PLSIG has defined what is believed to be a - complete and sufficient set of codes and rules for adequately representing - all of FORTRAN 77, and most of Fortran 90 in DWARF. While some support for - this has been implemented in dwarfout.c, further implementation and testing - is needed. - - GNU DWARF support for other languages (i.e. Pascal and Modula) is a moot - issue until there are GNU front-ends for these other languages. - - As currently defined, DWARF only describes a (binary) language which can - be used to communicate symbolic debugging information from a compiler - through an assembler and a linker, to a debugger. There is no clear - specification of what processing should be (or must be) done by the - assembler and/or the linker. Fortunately, the role of the assembler - is easily inferred (by anyone knowledgeable about assemblers) just by - looking at examples of assembly-level DWARF code. Sadly though, the - allowable (or required) processing steps performed by a linker are - harder to infer and (perhaps) even harder to agree upon. There are - several forms of very useful `post-processing' steps which intelligent - linkers *could* (in theory) perform on object files containing DWARF, - but any and all such link-time transformations are currently both disallowed - and unspecified. - - In particular, possible link-time transformations of DWARF code which could - provide significant benefits include (but are not limited to): - - Commonization of duplicate DIEs obtained from multiple input - (object) files. - - Cross-compilation type checking based upon DWARF type information - for objects and functions. - - Other possible `compacting' transformations designed to save disk - space and to reduce linker & debugger I/O activity. - -*/ - -#include "config.h" - -#ifdef DWARF_DEBUGGING_INFO -#include "system.h" -#include "dwarf.h" -#include "tree.h" -#include "flags.h" -#include "function.h" -#include "rtl.h" -#include "hard-reg-set.h" -#include "insn-config.h" -#include "reload.h" -#include "output.h" -#include "dwarf2asm.h" -#include "toplev.h" -#include "tm_p.h" -#include "debug.h" -#include "langhooks.h" - -/* NOTE: In the comments in this file, many references are made to - so called "Debugging Information Entries". For the sake of brevity, - this term is abbreviated to `DIE' throughout the remainder of this - file. */ - -/* Note that the implementation of C++ support herein is (as yet) unfinished. - If you want to try to complete it, more power to you. */ - -/* How to start an assembler comment. */ -#ifndef ASM_COMMENT_START -#define ASM_COMMENT_START ";#" -#endif - -/* How to print out a register name. */ -#ifndef PRINT_REG -#define PRINT_REG(RTX, CODE, FILE) \ - fprintf ((FILE), "%s", reg_names[REGNO (RTX)]) -#endif - -/* Define a macro which returns nonzero for any tagged type which is - used (directly or indirectly) in the specification of either some - function's return type or some formal parameter of some function. - We use this macro when we are operating in "terse" mode to help us - know what tagged types have to be represented in Dwarf (even in - terse mode) and which ones don't. - - A flag bit with this meaning really should be a part of the normal - GCC ..._TYPE nodes, but at the moment, there is no such bit defined - for these nodes. For now, we have to just fake it. It it safe for - us to simply return zero for all complete tagged types (which will - get forced out anyway if they were used in the specification of some - formal or return type) and nonzero for all incomplete tagged types. -*/ - -#define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0) - -/* Define a macro which returns nonzero for a TYPE_DECL which was - implicitly generated for a tagged type. - - Note that unlike the gcc front end (which generates a NULL named - TYPE_DECL node for each complete tagged type, each array type, and - each function type node created) the g++ front end generates a - _named_ TYPE_DECL node for each tagged type node created. - These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to - generate a DW_TAG_typedef DIE for them. */ -#define TYPE_DECL_IS_STUB(decl) \ - (DECL_NAME (decl) == NULL \ - || (DECL_ARTIFICIAL (decl) \ - && is_tagged_type (TREE_TYPE (decl)) \ - && decl == TYPE_STUB_DECL (TREE_TYPE (decl)))) - -/* Maximum size (in bytes) of an artificially generated label. */ - -#define MAX_ARTIFICIAL_LABEL_BYTES 30 - -/* Structure to keep track of source filenames. */ - -struct filename_entry { - unsigned number; - const char * name; -}; - -typedef struct filename_entry filename_entry; - -/* Pointer to an array of elements, each one having the structure above. */ - -static filename_entry *filename_table; - -/* Total number of entries in the table (i.e. array) pointed to by - `filename_table'. This is the *total* and includes both used and - unused slots. */ - -static unsigned ft_entries_allocated; - -/* Number of entries in the filename_table which are actually in use. */ - -static unsigned ft_entries; - -/* Size (in elements) of increments by which we may expand the filename - table. Actually, a single hunk of space of this size should be enough - for most typical programs. */ - -#define FT_ENTRIES_INCREMENT 64 - -/* Local pointer to the name of the main input file. Initialized in - dwarfout_init. */ - -static const char *primary_filename; - -/* Counter to generate unique names for DIEs. */ - -static unsigned next_unused_dienum = 1; - -/* Number of the DIE which is currently being generated. */ - -static unsigned current_dienum; - -/* Number to use for the special "pubname" label on the next DIE which - represents a function or data object defined in this compilation - unit which has "extern" linkage. */ - -static int next_pubname_number = 0; - -#define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1] - -/* Pointer to a dynamically allocated list of pre-reserved and still - pending sibling DIE numbers. Note that this list will grow as needed. */ - -static unsigned *pending_sibling_stack; - -/* Counter to keep track of the number of pre-reserved and still pending - sibling DIE numbers. */ - -static unsigned pending_siblings; - -/* The currently allocated size of the above list (expressed in number of - list elements). */ - -static unsigned pending_siblings_allocated; - -/* Size (in elements) of increments by which we may expand the pending - sibling stack. Actually, a single hunk of space of this size should - be enough for most typical programs. */ - -#define PENDING_SIBLINGS_INCREMENT 64 - -/* Nonzero if we are performing our file-scope finalization pass and if - we should force out Dwarf descriptions of any and all file-scope - tagged types which are still incomplete types. */ - -static int finalizing = 0; - -/* A pointer to the base of a list of pending types which we haven't - generated DIEs for yet, but which we will have to come back to - later on. */ - -static tree *pending_types_list; - -/* Number of elements currently allocated for the pending_types_list. */ - -static unsigned pending_types_allocated; - -/* Number of elements of pending_types_list currently in use. */ - -static unsigned pending_types; - -/* Size (in elements) of increments by which we may expand the pending - types list. Actually, a single hunk of space of this size should - be enough for most typical programs. */ - -#define PENDING_TYPES_INCREMENT 64 - -/* A pointer to the base of a list of incomplete types which might be - completed at some later time. */ - -static tree *incomplete_types_list; - -/* Number of elements currently allocated for the incomplete_types_list. */ -static unsigned incomplete_types_allocated; - -/* Number of elements of incomplete_types_list currently in use. */ -static unsigned incomplete_types; - -/* Size (in elements) of increments by which we may expand the incomplete - types list. Actually, a single hunk of space of this size should - be enough for most typical programs. */ -#define INCOMPLETE_TYPES_INCREMENT 64 - -/* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init. - This is used in a hack to help us get the DIEs describing types of - formal parameters to come *after* all of the DIEs describing the formal - parameters themselves. That's necessary in order to be compatible - with what the brain-damaged svr4 SDB debugger requires. */ - -static tree fake_containing_scope; - -/* A pointer to the ..._DECL node which we have most recently been working - on. We keep this around just in case something about it looks screwy - and we want to tell the user what the source coordinates for the actual - declaration are. */ - -static tree dwarf_last_decl; - -/* A flag indicating that we are emitting the member declarations of a - class, so member functions and variables should not be entirely emitted. - This is a kludge to avoid passing a second argument to output_*_die. */ - -static int in_class; - -/* Forward declarations for functions defined in this file. */ - -static void dwarfout_init PARAMS ((const char *)); -static void dwarfout_finish PARAMS ((const char *)); -static void dwarfout_define PARAMS ((unsigned int, const char *)); -static void dwarfout_undef PARAMS ((unsigned int, const char *)); -static void dwarfout_start_source_file PARAMS ((unsigned, const char *)); -static void dwarfout_start_source_file_check PARAMS ((unsigned, const char *)); -static void dwarfout_end_source_file PARAMS ((unsigned)); -static void dwarfout_end_source_file_check PARAMS ((unsigned)); -static void dwarfout_begin_block PARAMS ((unsigned, unsigned)); -static void dwarfout_end_block PARAMS ((unsigned, unsigned)); -static void dwarfout_end_epilogue PARAMS ((unsigned int, const char *)); -static void dwarfout_source_line PARAMS ((unsigned int, const char *)); -static void dwarfout_end_prologue PARAMS ((unsigned int, const char *)); -static void dwarfout_end_function PARAMS ((unsigned int)); -static void dwarfout_function_decl PARAMS ((tree)); -static void dwarfout_global_decl PARAMS ((tree)); -static void dwarfout_deferred_inline_function PARAMS ((tree)); -static void dwarfout_file_scope_decl PARAMS ((tree , int)); -static const char *dwarf_tag_name PARAMS ((unsigned)); -static const char *dwarf_attr_name PARAMS ((unsigned)); -static const char *dwarf_stack_op_name PARAMS ((unsigned)); -static const char *dwarf_typemod_name PARAMS ((unsigned)); -static const char *dwarf_fmt_byte_name PARAMS ((unsigned)); -static const char *dwarf_fund_type_name PARAMS ((unsigned)); -static tree decl_ultimate_origin PARAMS ((tree)); -static tree block_ultimate_origin PARAMS ((tree)); -static tree decl_class_context PARAMS ((tree)); -#if 0 -static void output_unsigned_leb128 PARAMS ((unsigned long)); -static void output_signed_leb128 PARAMS ((long)); -#endif -static int fundamental_type_code PARAMS ((tree)); -static tree root_type_1 PARAMS ((tree, int)); -static tree root_type PARAMS ((tree)); -static void write_modifier_bytes_1 PARAMS ((tree, int, int, int)); -static void write_modifier_bytes PARAMS ((tree, int, int)); -static inline int type_is_fundamental PARAMS ((tree)); -static void equate_decl_number_to_die_number PARAMS ((tree)); -static inline void equate_type_number_to_die_number PARAMS ((tree)); -static void output_reg_number PARAMS ((rtx)); -static void output_mem_loc_descriptor PARAMS ((rtx)); -static void output_loc_descriptor PARAMS ((rtx)); -static void output_bound_representation PARAMS ((tree, unsigned, int)); -static void output_enumeral_list PARAMS ((tree)); -static inline HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); -static inline tree field_type PARAMS ((tree)); -static inline unsigned int simple_type_align_in_bits PARAMS ((tree)); -static inline unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); -static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); -static inline void sibling_attribute PARAMS ((void)); -static void location_attribute PARAMS ((rtx)); -static void data_member_location_attribute PARAMS ((tree)); -static void const_value_attribute PARAMS ((rtx)); -static void location_or_const_value_attribute PARAMS ((tree)); -static inline void name_attribute PARAMS ((const char *)); -static inline void fund_type_attribute PARAMS ((unsigned)); -static void mod_fund_type_attribute PARAMS ((tree, int, int)); -static inline void user_def_type_attribute PARAMS ((tree)); -static void mod_u_d_type_attribute PARAMS ((tree, int, int)); -#ifdef USE_ORDERING_ATTRIBUTE -static inline void ordering_attribute PARAMS ((unsigned)); -#endif /* defined(USE_ORDERING_ATTRIBUTE) */ -static void subscript_data_attribute PARAMS ((tree)); -static void byte_size_attribute PARAMS ((tree)); -static inline void bit_offset_attribute PARAMS ((tree)); -static inline void bit_size_attribute PARAMS ((tree)); -static inline void element_list_attribute PARAMS ((tree)); -static inline void stmt_list_attribute PARAMS ((const char *)); -static inline void low_pc_attribute PARAMS ((const char *)); -static inline void high_pc_attribute PARAMS ((const char *)); -static inline void body_begin_attribute PARAMS ((const char *)); -static inline void body_end_attribute PARAMS ((const char *)); -static inline void language_attribute PARAMS ((unsigned)); -static inline void member_attribute PARAMS ((tree)); -#if 0 -static inline void string_length_attribute PARAMS ((tree)); -#endif -static inline void comp_dir_attribute PARAMS ((const char *)); -static inline void sf_names_attribute PARAMS ((const char *)); -static inline void src_info_attribute PARAMS ((const char *)); -static inline void mac_info_attribute PARAMS ((const char *)); -static inline void prototyped_attribute PARAMS ((tree)); -static inline void producer_attribute PARAMS ((const char *)); -static inline void inline_attribute PARAMS ((tree)); -static inline void containing_type_attribute PARAMS ((tree)); -static inline void abstract_origin_attribute PARAMS ((tree)); -#ifdef DWARF_DECL_COORDINATES -static inline void src_coords_attribute PARAMS ((unsigned, unsigned)); -#endif /* defined(DWARF_DECL_COORDINATES) */ -static inline void pure_or_virtual_attribute PARAMS ((tree)); -static void name_and_src_coords_attributes PARAMS ((tree)); -static void type_attribute PARAMS ((tree, int, int)); -static const char *type_tag PARAMS ((tree)); -static inline void dienum_push PARAMS ((void)); -static inline void dienum_pop PARAMS ((void)); -static inline tree member_declared_type PARAMS ((tree)); -static const char *function_start_label PARAMS ((tree)); -static void output_array_type_die PARAMS ((void *)); -static void output_set_type_die PARAMS ((void *)); -#if 0 -static void output_entry_point_die PARAMS ((void *)); -#endif -static void output_inlined_enumeration_type_die PARAMS ((void *)); -static void output_inlined_structure_type_die PARAMS ((void *)); -static void output_inlined_union_type_die PARAMS ((void *)); -static void output_enumeration_type_die PARAMS ((void *)); -static void output_formal_parameter_die PARAMS ((void *)); -static void output_global_subroutine_die PARAMS ((void *)); -static void output_global_variable_die PARAMS ((void *)); -static void output_label_die PARAMS ((void *)); -static void output_lexical_block_die PARAMS ((void *)); -static void output_inlined_subroutine_die PARAMS ((void *)); -static void output_local_variable_die PARAMS ((void *)); -static void output_member_die PARAMS ((void *)); -#if 0 -static void output_pointer_type_die PARAMS ((void *)); -static void output_reference_type_die PARAMS ((void *)); -#endif -static void output_ptr_to_mbr_type_die PARAMS ((void *)); -static void output_compile_unit_die PARAMS ((void *)); -static void output_string_type_die PARAMS ((void *)); -static void output_inheritance_die PARAMS ((void *)); -static void output_structure_type_die PARAMS ((void *)); -static void output_local_subroutine_die PARAMS ((void *)); -static void output_subroutine_type_die PARAMS ((void *)); -static void output_typedef_die PARAMS ((void *)); -static void output_union_type_die PARAMS ((void *)); -static void output_unspecified_parameters_die PARAMS ((void *)); -static void output_padded_null_die PARAMS ((void *)); -static void output_die PARAMS ((void (*)(void *), void *)); -static void end_sibling_chain PARAMS ((void)); -static void output_formal_types PARAMS ((tree)); -static void pend_type PARAMS ((tree)); -static int type_ok_for_scope PARAMS ((tree, tree)); -static void output_pending_types_for_scope PARAMS ((tree)); -static void output_type PARAMS ((tree, tree)); -static void output_tagged_type_instantiation PARAMS ((tree)); -static void output_block PARAMS ((tree, int)); -static void output_decls_for_scope PARAMS ((tree, int)); -static void output_decl PARAMS ((tree, tree)); -static void shuffle_filename_entry PARAMS ((filename_entry *)); -static void generate_new_sfname_entry PARAMS ((void)); -static unsigned lookup_filename PARAMS ((const char *)); -static void generate_srcinfo_entry PARAMS ((unsigned, unsigned)); -static void generate_macinfo_entry PARAMS ((unsigned int, rtx, - const char *)); -static int is_pseudo_reg PARAMS ((rtx)); -static tree type_main_variant PARAMS ((tree)); -static int is_tagged_type PARAMS ((tree)); -static int is_redundant_typedef PARAMS ((tree)); -static void add_incomplete_type PARAMS ((tree)); -static void retry_incomplete_types PARAMS ((void)); - -/* Definitions of defaults for assembler-dependent names of various - pseudo-ops and section names. - - Theses may be overridden in your tm.h file (if necessary) for your - particular assembler. The default values provided here correspond to - what is expected by "standard" AT&T System V.4 assemblers. */ - -#ifndef FILE_ASM_OP -#define FILE_ASM_OP "\t.file\t" -#endif -#ifndef SET_ASM_OP -#define SET_ASM_OP "\t.set\t" -#endif - -/* Pseudo-ops for pushing the current section onto the section stack (and - simultaneously changing to a new section) and for poping back to the - section we were in immediately before this one. Note that most svr4 - assemblers only maintain a one level stack... you can push all the - sections you want, but you can only pop out one level. (The sparc - svr4 assembler is an exception to this general rule.) That's - OK because we only use at most one level of the section stack herein. */ - -#ifndef PUSHSECTION_ASM_OP -#define PUSHSECTION_ASM_OP "\t.section\t" -#endif -#ifndef POPSECTION_ASM_OP -#define POPSECTION_ASM_OP "\t.previous" -#endif - -/* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below) - to print the PUSHSECTION_ASM_OP and the section name. The default here - works for almost all svr4 assemblers, except for the sparc, where the - section name must be enclosed in double quotes. (See sparcv4.h.) */ - -#ifndef PUSHSECTION_FORMAT -#define PUSHSECTION_FORMAT "%s%s\n" -#endif - -#ifndef DEBUG_SECTION -#define DEBUG_SECTION ".debug" -#endif -#ifndef LINE_SECTION -#define LINE_SECTION ".line" -#endif -#ifndef DEBUG_SFNAMES_SECTION -#define DEBUG_SFNAMES_SECTION ".debug_sfnames" -#endif -#ifndef DEBUG_SRCINFO_SECTION -#define DEBUG_SRCINFO_SECTION ".debug_srcinfo" -#endif -#ifndef DEBUG_MACINFO_SECTION -#define DEBUG_MACINFO_SECTION ".debug_macinfo" -#endif -#ifndef DEBUG_PUBNAMES_SECTION -#define DEBUG_PUBNAMES_SECTION ".debug_pubnames" -#endif -#ifndef DEBUG_ARANGES_SECTION -#define DEBUG_ARANGES_SECTION ".debug_aranges" -#endif -#ifndef TEXT_SECTION_NAME -#define TEXT_SECTION_NAME ".text" -#endif -#ifndef DATA_SECTION_NAME -#define DATA_SECTION_NAME ".data" -#endif -#ifndef DATA1_SECTION_NAME -#define DATA1_SECTION_NAME ".data1" -#endif -#ifndef RODATA_SECTION_NAME -#define RODATA_SECTION_NAME ".rodata" -#endif -#ifndef RODATA1_SECTION_NAME -#define RODATA1_SECTION_NAME ".rodata1" -#endif -#ifndef BSS_SECTION_NAME -#define BSS_SECTION_NAME ".bss" -#endif - -/* Definitions of defaults for formats and names of various special - (artificial) labels which may be generated within this file (when - the -g options is used and DWARF_DEBUGGING_INFO is in effect. - - If necessary, these may be overridden from within your tm.h file, - but typically, you should never need to override these. - - These labels have been hacked (temporarily) so that they all begin with - a `.L' sequence so as to appease the stock sparc/svr4 assembler and the - stock m88k/svr4 assembler, both of which need to see .L at the start of - a label in order to prevent that label from going into the linker symbol - table). When I get time, I'll have to fix this the right way so that we - will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein, - but that will require a rather massive set of changes. For the moment, - the following definitions out to produce the right results for all svr4 - and svr3 assemblers. -- rfg -*/ - -#ifndef TEXT_BEGIN_LABEL -#define TEXT_BEGIN_LABEL "*.L_text_b" -#endif -#ifndef TEXT_END_LABEL -#define TEXT_END_LABEL "*.L_text_e" -#endif - -#ifndef DATA_BEGIN_LABEL -#define DATA_BEGIN_LABEL "*.L_data_b" -#endif -#ifndef DATA_END_LABEL -#define DATA_END_LABEL "*.L_data_e" -#endif - -#ifndef DATA1_BEGIN_LABEL -#define DATA1_BEGIN_LABEL "*.L_data1_b" -#endif -#ifndef DATA1_END_LABEL -#define DATA1_END_LABEL "*.L_data1_e" -#endif - -#ifndef RODATA_BEGIN_LABEL -#define RODATA_BEGIN_LABEL "*.L_rodata_b" -#endif -#ifndef RODATA_END_LABEL -#define RODATA_END_LABEL "*.L_rodata_e" -#endif - -#ifndef RODATA1_BEGIN_LABEL -#define RODATA1_BEGIN_LABEL "*.L_rodata1_b" -#endif -#ifndef RODATA1_END_LABEL -#define RODATA1_END_LABEL "*.L_rodata1_e" -#endif - -#ifndef BSS_BEGIN_LABEL -#define BSS_BEGIN_LABEL "*.L_bss_b" -#endif -#ifndef BSS_END_LABEL -#define BSS_END_LABEL "*.L_bss_e" -#endif - -#ifndef LINE_BEGIN_LABEL -#define LINE_BEGIN_LABEL "*.L_line_b" -#endif -#ifndef LINE_LAST_ENTRY_LABEL -#define LINE_LAST_ENTRY_LABEL "*.L_line_last" -#endif -#ifndef LINE_END_LABEL -#define LINE_END_LABEL "*.L_line_e" -#endif - -#ifndef DEBUG_BEGIN_LABEL -#define DEBUG_BEGIN_LABEL "*.L_debug_b" -#endif -#ifndef SFNAMES_BEGIN_LABEL -#define SFNAMES_BEGIN_LABEL "*.L_sfnames_b" -#endif -#ifndef SRCINFO_BEGIN_LABEL -#define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b" -#endif -#ifndef MACINFO_BEGIN_LABEL -#define MACINFO_BEGIN_LABEL "*.L_macinfo_b" -#endif - -#ifndef DEBUG_ARANGES_BEGIN_LABEL -#define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin" -#endif -#ifndef DEBUG_ARANGES_END_LABEL -#define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end" -#endif - -#ifndef DIE_BEGIN_LABEL_FMT -#define DIE_BEGIN_LABEL_FMT "*.L_D%u" -#endif -#ifndef DIE_END_LABEL_FMT -#define DIE_END_LABEL_FMT "*.L_D%u_e" -#endif -#ifndef PUB_DIE_LABEL_FMT -#define PUB_DIE_LABEL_FMT "*.L_P%u" -#endif -#ifndef BLOCK_BEGIN_LABEL_FMT -#define BLOCK_BEGIN_LABEL_FMT "*.L_B%u" -#endif -#ifndef BLOCK_END_LABEL_FMT -#define BLOCK_END_LABEL_FMT "*.L_B%u_e" -#endif -#ifndef SS_BEGIN_LABEL_FMT -#define SS_BEGIN_LABEL_FMT "*.L_s%u" -#endif -#ifndef SS_END_LABEL_FMT -#define SS_END_LABEL_FMT "*.L_s%u_e" -#endif -#ifndef EE_BEGIN_LABEL_FMT -#define EE_BEGIN_LABEL_FMT "*.L_e%u" -#endif -#ifndef EE_END_LABEL_FMT -#define EE_END_LABEL_FMT "*.L_e%u_e" -#endif -#ifndef MT_BEGIN_LABEL_FMT -#define MT_BEGIN_LABEL_FMT "*.L_t%u" -#endif -#ifndef MT_END_LABEL_FMT -#define MT_END_LABEL_FMT "*.L_t%u_e" -#endif -#ifndef LOC_BEGIN_LABEL_FMT -#define LOC_BEGIN_LABEL_FMT "*.L_l%u" -#endif -#ifndef LOC_END_LABEL_FMT -#define LOC_END_LABEL_FMT "*.L_l%u_e" -#endif -#ifndef BOUND_BEGIN_LABEL_FMT -#define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c" -#endif -#ifndef BOUND_END_LABEL_FMT -#define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e" -#endif -#ifndef BODY_BEGIN_LABEL_FMT -#define BODY_BEGIN_LABEL_FMT "*.L_b%u" -#endif -#ifndef BODY_END_LABEL_FMT -#define BODY_END_LABEL_FMT "*.L_b%u_e" -#endif -#ifndef FUNC_END_LABEL_FMT -#define FUNC_END_LABEL_FMT "*.L_f%u_e" -#endif -#ifndef TYPE_NAME_FMT -#define TYPE_NAME_FMT "*.L_T%u" -#endif -#ifndef DECL_NAME_FMT -#define DECL_NAME_FMT "*.L_E%u" -#endif -#ifndef LINE_CODE_LABEL_FMT -#define LINE_CODE_LABEL_FMT "*.L_LC%u" -#endif -#ifndef SFNAMES_ENTRY_LABEL_FMT -#define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u" -#endif -#ifndef LINE_ENTRY_LABEL_FMT -#define LINE_ENTRY_LABEL_FMT "*.L_LE%u" -#endif - -/* Definitions of defaults for various types of primitive assembly language - output operations. - - If necessary, these may be overridden from within your tm.h file, - but typically, you shouldn't need to override these. */ - -#ifndef ASM_OUTPUT_PUSH_SECTION -#define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \ - fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION) -#endif - -#ifndef ASM_OUTPUT_POP_SECTION -#define ASM_OUTPUT_POP_SECTION(FILE) \ - fprintf ((FILE), "%s\n", POPSECTION_ASM_OP) -#endif - -#ifndef ASM_OUTPUT_DWARF_DELTA2 -#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ - dw2_asm_output_delta (2, LABEL1, LABEL2, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_DELTA4 -#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ - dw2_asm_output_delta (4, LABEL1, LABEL2, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_TAG -#define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \ - dw2_asm_output_data (2, TAG, "%s", dwarf_tag_name (TAG)); -#endif - -#ifndef ASM_OUTPUT_DWARF_ATTRIBUTE -#define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \ - dw2_asm_output_data (2, ATTR, "%s", dwarf_attr_name (ATTR)) -#endif - -#ifndef ASM_OUTPUT_DWARF_STACK_OP -#define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \ - dw2_asm_output_data (1, OP, "%s", dwarf_stack_op_name (OP)) -#endif - -#ifndef ASM_OUTPUT_DWARF_FUND_TYPE -#define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \ - dw2_asm_output_data (2, FT, "%s", dwarf_fund_type_name (FT)) -#endif - -#ifndef ASM_OUTPUT_DWARF_FMT_BYTE -#define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \ - dw2_asm_output_data (1, FMT, "%s", dwarf_fmt_byte_name (FMT)); -#endif - -#ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER -#define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \ - dw2_asm_output_data (1, MOD, "%s", dwarf_typemod_name (MOD)); -#endif - -#ifndef ASM_OUTPUT_DWARF_ADDR -#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ - dw2_asm_output_addr (4, LABEL, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_ADDR_CONST -#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ - dw2_asm_output_addr_rtx (4, RTX, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_REF -#define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \ - dw2_asm_output_addr (4, LABEL, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_DATA1 -#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ - dw2_asm_output_data (1, VALUE, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_DATA2 -#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ - dw2_asm_output_data (2, VALUE, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_DATA4 -#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ - dw2_asm_output_data (4, VALUE, NULL) -#endif - -#ifndef ASM_OUTPUT_DWARF_DATA8 -#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ - dw2_asm_output_data (8, VALUE, NULL) -#endif - -/* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to - NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE - based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is - defined, we call it, then issue the line feed. If not, we supply a - default definition of calling ASM_OUTPUT_ASCII */ - -#ifndef ASM_OUTPUT_DWARF_STRING -#define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \ - ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1) -#else -#define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \ - ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n") -#endif - - -/* The debug hooks structure. */ -const struct gcc_debug_hooks dwarf_debug_hooks = -{ - dwarfout_init, - dwarfout_finish, - dwarfout_define, - dwarfout_undef, - dwarfout_start_source_file_check, - dwarfout_end_source_file_check, - dwarfout_begin_block, - dwarfout_end_block, - debug_true_tree, /* ignore_block */ - dwarfout_source_line, /* source_line */ - dwarfout_source_line, /* begin_prologue */ - dwarfout_end_prologue, - dwarfout_end_epilogue, - debug_nothing_tree, /* begin_function */ - dwarfout_end_function, - dwarfout_function_decl, - dwarfout_global_decl, - dwarfout_deferred_inline_function, - debug_nothing_tree, /* outlining_inline_function */ - debug_nothing_rtx /* label */ -}; - -/************************ general utility functions **************************/ - -static inline int -is_pseudo_reg (rtl) - rtx rtl; -{ - return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) - || ((GET_CODE (rtl) == SUBREG) - && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER))); -} - -static inline tree -type_main_variant (type) - tree type; -{ - type = TYPE_MAIN_VARIANT (type); - - /* There really should be only one main variant among any group of variants - of a given type (and all of the MAIN_VARIANT values for all members of - the group should point to that one type) but sometimes the C front-end - messes this up for array types, so we work around that bug here. */ - - if (TREE_CODE (type) == ARRAY_TYPE) - { - while (type != TYPE_MAIN_VARIANT (type)) - type = TYPE_MAIN_VARIANT (type); - } - - return type; -} - -/* Return nonzero if the given type node represents a tagged type. */ - -static inline int -is_tagged_type (type) - tree type; -{ - enum tree_code code = TREE_CODE (type); - - return (code == RECORD_TYPE || code == UNION_TYPE - || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); -} - -static const char * -dwarf_tag_name (tag) - unsigned tag; -{ - switch (tag) - { - case TAG_padding: return "TAG_padding"; - case TAG_array_type: return "TAG_array_type"; - case TAG_class_type: return "TAG_class_type"; - case TAG_entry_point: return "TAG_entry_point"; - case TAG_enumeration_type: return "TAG_enumeration_type"; - case TAG_formal_parameter: return "TAG_formal_parameter"; - case TAG_global_subroutine: return "TAG_global_subroutine"; - case TAG_global_variable: return "TAG_global_variable"; - case TAG_label: return "TAG_label"; - case TAG_lexical_block: return "TAG_lexical_block"; - case TAG_local_variable: return "TAG_local_variable"; - case TAG_member: return "TAG_member"; - case TAG_pointer_type: return "TAG_pointer_type"; - case TAG_reference_type: return "TAG_reference_type"; - case TAG_compile_unit: return "TAG_compile_unit"; - case TAG_string_type: return "TAG_string_type"; - case TAG_structure_type: return "TAG_structure_type"; - case TAG_subroutine: return "TAG_subroutine"; - case TAG_subroutine_type: return "TAG_subroutine_type"; - case TAG_typedef: return "TAG_typedef"; - case TAG_union_type: return "TAG_union_type"; - case TAG_unspecified_parameters: return "TAG_unspecified_parameters"; - case TAG_variant: return "TAG_variant"; - case TAG_common_block: return "TAG_common_block"; - case TAG_common_inclusion: return "TAG_common_inclusion"; - case TAG_inheritance: return "TAG_inheritance"; - case TAG_inlined_subroutine: return "TAG_inlined_subroutine"; - case TAG_module: return "TAG_module"; - case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type"; - case TAG_set_type: return "TAG_set_type"; - case TAG_subrange_type: return "TAG_subrange_type"; - case TAG_with_stmt: return "TAG_with_stmt"; - - /* GNU extensions. */ - - case TAG_format_label: return "TAG_format_label"; - case TAG_namelist: return "TAG_namelist"; - case TAG_function_template: return "TAG_function_template"; - case TAG_class_template: return "TAG_class_template"; - - default: return "TAG_<unknown>"; - } -} - -static const char * -dwarf_attr_name (attr) - unsigned attr; -{ - switch (attr) - { - case AT_sibling: return "AT_sibling"; - case AT_location: return "AT_location"; - case AT_name: return "AT_name"; - case AT_fund_type: return "AT_fund_type"; - case AT_mod_fund_type: return "AT_mod_fund_type"; - case AT_user_def_type: return "AT_user_def_type"; - case AT_mod_u_d_type: return "AT_mod_u_d_type"; - case AT_ordering: return "AT_ordering"; - case AT_subscr_data: return "AT_subscr_data"; - case AT_byte_size: return "AT_byte_size"; - case AT_bit_offset: return "AT_bit_offset"; - case AT_bit_size: return "AT_bit_size"; - case AT_element_list: return "AT_element_list"; - case AT_stmt_list: return "AT_stmt_list"; - case AT_low_pc: return "AT_low_pc"; - case AT_high_pc: return "AT_high_pc"; - case AT_language: return "AT_language"; - case AT_member: return "AT_member"; - case AT_discr: return "AT_discr"; - case AT_discr_value: return "AT_discr_value"; - case AT_string_length: return "AT_string_length"; - case AT_common_reference: return "AT_common_reference"; - case AT_comp_dir: return "AT_comp_dir"; - case AT_const_value_string: return "AT_const_value_string"; - case AT_const_value_data2: return "AT_const_value_data2"; - case AT_const_value_data4: return "AT_const_value_data4"; - case AT_const_value_data8: return "AT_const_value_data8"; - case AT_const_value_block2: return "AT_const_value_block2"; - case AT_const_value_block4: return "AT_const_value_block4"; - case AT_containing_type: return "AT_containing_type"; - case AT_default_value_addr: return "AT_default_value_addr"; - case AT_default_value_data2: return "AT_default_value_data2"; - case AT_default_value_data4: return "AT_default_value_data4"; - case AT_default_value_data8: return "AT_default_value_data8"; - case AT_default_value_string: return "AT_default_value_string"; - case AT_friends: return "AT_friends"; - case AT_inline: return "AT_inline"; - case AT_is_optional: return "AT_is_optional"; - case AT_lower_bound_ref: return "AT_lower_bound_ref"; - case AT_lower_bound_data2: return "AT_lower_bound_data2"; - case AT_lower_bound_data4: return "AT_lower_bound_data4"; - case AT_lower_bound_data8: return "AT_lower_bound_data8"; - case AT_private: return "AT_private"; - case AT_producer: return "AT_producer"; - case AT_program: return "AT_program"; - case AT_protected: return "AT_protected"; - case AT_prototyped: return "AT_prototyped"; - case AT_public: return "AT_public"; - case AT_pure_virtual: return "AT_pure_virtual"; - case AT_return_addr: return "AT_return_addr"; - case AT_abstract_origin: return "AT_abstract_origin"; - case AT_start_scope: return "AT_start_scope"; - case AT_stride_size: return "AT_stride_size"; - case AT_upper_bound_ref: return "AT_upper_bound_ref"; - case AT_upper_bound_data2: return "AT_upper_bound_data2"; - case AT_upper_bound_data4: return "AT_upper_bound_data4"; - case AT_upper_bound_data8: return "AT_upper_bound_data8"; - case AT_virtual: return "AT_virtual"; - - /* GNU extensions */ - - case AT_sf_names: return "AT_sf_names"; - case AT_src_info: return "AT_src_info"; - case AT_mac_info: return "AT_mac_info"; - case AT_src_coords: return "AT_src_coords"; - case AT_body_begin: return "AT_body_begin"; - case AT_body_end: return "AT_body_end"; - - default: return "AT_<unknown>"; - } -} - -static const char * -dwarf_stack_op_name (op) - unsigned op; -{ - switch (op) - { - case OP_REG: return "OP_REG"; - case OP_BASEREG: return "OP_BASEREG"; - case OP_ADDR: return "OP_ADDR"; - case OP_CONST: return "OP_CONST"; - case OP_DEREF2: return "OP_DEREF2"; - case OP_DEREF4: return "OP_DEREF4"; - case OP_ADD: return "OP_ADD"; - default: return "OP_<unknown>"; - } -} - -static const char * -dwarf_typemod_name (mod) - unsigned mod; -{ - switch (mod) - { - case MOD_pointer_to: return "MOD_pointer_to"; - case MOD_reference_to: return "MOD_reference_to"; - case MOD_const: return "MOD_const"; - case MOD_volatile: return "MOD_volatile"; - default: return "MOD_<unknown>"; - } -} - -static const char * -dwarf_fmt_byte_name (fmt) - unsigned fmt; -{ - switch (fmt) - { - case FMT_FT_C_C: return "FMT_FT_C_C"; - case FMT_FT_C_X: return "FMT_FT_C_X"; - case FMT_FT_X_C: return "FMT_FT_X_C"; - case FMT_FT_X_X: return "FMT_FT_X_X"; - case FMT_UT_C_C: return "FMT_UT_C_C"; - case FMT_UT_C_X: return "FMT_UT_C_X"; - case FMT_UT_X_C: return "FMT_UT_X_C"; - case FMT_UT_X_X: return "FMT_UT_X_X"; - case FMT_ET: return "FMT_ET"; - default: return "FMT_<unknown>"; - } -} - -static const char * -dwarf_fund_type_name (ft) - unsigned ft; -{ - switch (ft) - { - case FT_char: return "FT_char"; - case FT_signed_char: return "FT_signed_char"; - case FT_unsigned_char: return "FT_unsigned_char"; - case FT_short: return "FT_short"; - case FT_signed_short: return "FT_signed_short"; - case FT_unsigned_short: return "FT_unsigned_short"; - case FT_integer: return "FT_integer"; - case FT_signed_integer: return "FT_signed_integer"; - case FT_unsigned_integer: return "FT_unsigned_integer"; - case FT_long: return "FT_long"; - case FT_signed_long: return "FT_signed_long"; - case FT_unsigned_long: return "FT_unsigned_long"; - case FT_pointer: return "FT_pointer"; - case FT_float: return "FT_float"; - case FT_dbl_prec_float: return "FT_dbl_prec_float"; - case FT_ext_prec_float: return "FT_ext_prec_float"; - case FT_complex: return "FT_complex"; - case FT_dbl_prec_complex: return "FT_dbl_prec_complex"; - case FT_void: return "FT_void"; - case FT_boolean: return "FT_boolean"; - case FT_ext_prec_complex: return "FT_ext_prec_complex"; - case FT_label: return "FT_label"; - - /* GNU extensions. */ - - case FT_long_long: return "FT_long_long"; - case FT_signed_long_long: return "FT_signed_long_long"; - case FT_unsigned_long_long: return "FT_unsigned_long_long"; - - case FT_int8: return "FT_int8"; - case FT_signed_int8: return "FT_signed_int8"; - case FT_unsigned_int8: return "FT_unsigned_int8"; - case FT_int16: return "FT_int16"; - case FT_signed_int16: return "FT_signed_int16"; - case FT_unsigned_int16: return "FT_unsigned_int16"; - case FT_int32: return "FT_int32"; - case FT_signed_int32: return "FT_signed_int32"; - case FT_unsigned_int32: return "FT_unsigned_int32"; - case FT_int64: return "FT_int64"; - case FT_signed_int64: return "FT_signed_int64"; - case FT_unsigned_int64: return "FT_unsigned_int64"; - case FT_int128: return "FT_int128"; - case FT_signed_int128: return "FT_signed_int128"; - case FT_unsigned_int128: return "FT_unsigned_int128"; - - case FT_real32: return "FT_real32"; - case FT_real64: return "FT_real64"; - case FT_real96: return "FT_real96"; - case FT_real128: return "FT_real128"; - - default: return "FT_<unknown>"; - } -} - -/* Determine the "ultimate origin" of a decl. The decl may be an - inlined instance of an inlined instance of a decl which is local - to an inline function, so we have to trace all of the way back - through the origin chain to find out what sort of node actually - served as the original seed for the given block. */ - -static tree -decl_ultimate_origin (decl) - tree decl; -{ -#ifdef ENABLE_CHECKING - if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) - /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the - most distant ancestor, this should never happen. */ - abort (); -#endif - - return DECL_ABSTRACT_ORIGIN (decl); -} - -/* Determine the "ultimate origin" of a block. The block may be an - inlined instance of an inlined instance of a block which is local - to an inline function, so we have to trace all of the way back - through the origin chain to find out what sort of node actually - served as the original seed for the given block. */ - -static tree -block_ultimate_origin (block) - tree block; -{ - tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); - - if (immediate_origin == NULL) - return NULL; - else - { - tree ret_val; - tree lookahead = immediate_origin; - - do - { - ret_val = lookahead; - lookahead = (TREE_CODE (ret_val) == BLOCK) - ? BLOCK_ABSTRACT_ORIGIN (ret_val) - : NULL; - } - while (lookahead != NULL && lookahead != ret_val); - return ret_val; - } -} - -/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT - of a virtual function may refer to a base class, so we check the 'this' - parameter. */ - -static tree -decl_class_context (decl) - tree decl; -{ - tree context = NULL_TREE; - if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) - context = DECL_CONTEXT (decl); - else - context = TYPE_MAIN_VARIANT - (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); - - if (context && !TYPE_P (context)) - context = NULL_TREE; - - return context; -} - -#if 0 -static void -output_unsigned_leb128 (value) - unsigned long value; -{ - unsigned long orig_value = value; - - do - { - unsigned byte = (value & 0x7f); - - value >>= 7; - if (value != 0) /* more bytes to follow */ - byte |= 0x80; - dw2_asm_output_data (1, byte, "\t%s ULEB128 number - value = %lu", - orig_value); - } - while (value != 0); -} - -static void -output_signed_leb128 (value) - long value; -{ - long orig_value = value; - int negative = (value < 0); - int more; - - do - { - unsigned byte = (value & 0x7f); - - value >>= 7; - if (negative) - value |= 0xfe000000; /* manually sign extend */ - if (((value == 0) && ((byte & 0x40) == 0)) - || ((value == -1) && ((byte & 0x40) == 1))) - more = 0; - else - { - byte |= 0x80; - more = 1; - } - dw2_asm_output_data (1, byte, "\t%s SLEB128 number - value = %ld", - orig_value); - } - while (more); -} -#endif - -/**************** utility functions for attribute functions ******************/ - -/* Given a pointer to a tree node for some type, return a Dwarf fundamental - type code for the given type. - - This routine must only be called for GCC type nodes that correspond to - Dwarf fundamental types. - - The current Dwarf draft specification calls for Dwarf fundamental types - to accurately reflect the fact that a given type was either a "plain" - integral type or an explicitly "signed" integral type. Unfortunately, - we can't always do this, because GCC may already have thrown away the - information about the precise way in which the type was originally - specified, as in: - - typedef signed int my_type; - - struct s { my_type f; }; - - Since we may be stuck here without enough information to do exactly - what is called for in the Dwarf draft specification, we do the best - that we can under the circumstances and always use the "plain" integral - fundamental type codes for int, short, and long types. That's probably - good enough. The additional accuracy called for in the current DWARF - draft specification is probably never even useful in practice. */ - -static int -fundamental_type_code (type) - tree type; -{ - if (TREE_CODE (type) == ERROR_MARK) - return 0; - - switch (TREE_CODE (type)) - { - case ERROR_MARK: - return FT_void; - - case VOID_TYPE: - return FT_void; - - case INTEGER_TYPE: - /* Carefully distinguish all the standard types of C, - without messing up if the language is not C. - Note that we check only for the names that contain spaces; - other names might occur by coincidence in other languages. */ - if (TYPE_NAME (type) != 0 - && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && DECL_NAME (TYPE_NAME (type)) != 0 - && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) - { - const char *const name = - IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); - - if (!strcmp (name, "unsigned char")) - return FT_unsigned_char; - if (!strcmp (name, "signed char")) - return FT_signed_char; - if (!strcmp (name, "unsigned int")) - return FT_unsigned_integer; - if (!strcmp (name, "short int")) - return FT_short; - if (!strcmp (name, "short unsigned int")) - return FT_unsigned_short; - if (!strcmp (name, "long int")) - return FT_long; - if (!strcmp (name, "long unsigned int")) - return FT_unsigned_long; - if (!strcmp (name, "long long int")) - return FT_long_long; /* Not grok'ed by svr4 SDB */ - if (!strcmp (name, "long long unsigned int")) - return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */ - } - - /* Most integer types will be sorted out above, however, for the - sake of special `array index' integer types, the following code - is also provided. */ - - if (TYPE_PRECISION (type) == INT_TYPE_SIZE) - return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer); - - if (TYPE_PRECISION (type) == LONG_TYPE_SIZE) - return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long); - - if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE) - return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long); - - if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE) - return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short); - - if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE) - return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char); - - if (TYPE_MODE (type) == TImode) - return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128); - - /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */ - if (TYPE_PRECISION (type) == 1) - return FT_boolean; - - abort (); - - case REAL_TYPE: - /* Carefully distinguish all the standard types of C, - without messing up if the language is not C. */ - if (TYPE_NAME (type) != 0 - && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && DECL_NAME (TYPE_NAME (type)) != 0 - && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) - { - const char *const name = - IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); - - /* Note that here we can run afoul of a serious bug in "classic" - svr4 SDB debuggers. They don't seem to understand the - FT_ext_prec_float type (even though they should). */ - - if (!strcmp (name, "long double")) - return FT_ext_prec_float; - } - - if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE) - { - /* On the SH, when compiling with -m3e or -m4-single-only, both - float and double are 32 bits. But since the debugger doesn't - know about the subtarget, it always thinks double is 64 bits. - So we have to tell the debugger that the type is float to - make the output of the 'print' command etc. readable. */ - if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32) - return FT_float; - return FT_dbl_prec_float; - } - if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) - return FT_float; - - /* Note that here we can run afoul of a serious bug in "classic" - svr4 SDB debuggers. They don't seem to understand the - FT_ext_prec_float type (even though they should). */ - - if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE) - return FT_ext_prec_float; - abort (); - - case COMPLEX_TYPE: - return FT_complex; /* GNU FORTRAN COMPLEX type. */ - - case CHAR_TYPE: - return FT_char; /* GNU Pascal CHAR type. Not used in C. */ - - case BOOLEAN_TYPE: - return FT_boolean; /* GNU FORTRAN BOOLEAN type. */ - - default: - abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ - } - return 0; -} - -/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to - the Dwarf "root" type for the given input type. The Dwarf "root" type - of a given type is generally the same as the given type, except that if - the given type is a pointer or reference type, then the root type of - the given type is the root type of the "basis" type for the pointer or - reference type. (This definition of the "root" type is recursive.) - Also, the root type of a `const' qualified type or a `volatile' - qualified type is the root type of the given type without the - qualifiers. */ - -static tree -root_type_1 (type, count) - tree type; - int count; -{ - /* Give up after searching 1000 levels, in case this is a recursive - pointer type. Such types are possible in Ada, but it is not possible - to represent them in DWARF1 debug info. */ - if (count > 1000) - return error_mark_node; - - switch (TREE_CODE (type)) - { - case ERROR_MARK: - return error_mark_node; - - case POINTER_TYPE: - case REFERENCE_TYPE: - return root_type_1 (TREE_TYPE (type), count+1); - - default: - return type; - } -} - -static tree -root_type (type) - tree type; -{ - type = root_type_1 (type, 0); - if (type != error_mark_node) - type = type_main_variant (type); - return type; -} - -/* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence - of zero or more Dwarf "type-modifier" bytes applicable to the type. */ - -static void -write_modifier_bytes_1 (type, decl_const, decl_volatile, count) - tree type; - int decl_const; - int decl_volatile; - int count; -{ - if (TREE_CODE (type) == ERROR_MARK) - return; - - /* Give up after searching 1000 levels, in case this is a recursive - pointer type. Such types are possible in Ada, but it is not possible - to represent them in DWARF1 debug info. */ - if (count > 1000) - return; - - if (TYPE_READONLY (type) || decl_const) - ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const); - if (TYPE_VOLATILE (type) || decl_volatile) - ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile); - switch (TREE_CODE (type)) - { - case POINTER_TYPE: - ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to); - write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1); - return; - - case REFERENCE_TYPE: - ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to); - write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1); - return; - - case ERROR_MARK: - default: - return; - } -} - -static void -write_modifier_bytes (type, decl_const, decl_volatile) - tree type; - int decl_const; - int decl_volatile; -{ - write_modifier_bytes_1 (type, decl_const, decl_volatile, 0); -} - -/* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the - given input type is a Dwarf "fundamental" type. Otherwise return zero. */ - -static inline int -type_is_fundamental (type) - tree type; -{ - switch (TREE_CODE (type)) - { - case ERROR_MARK: - case VOID_TYPE: - case INTEGER_TYPE: - case REAL_TYPE: - case COMPLEX_TYPE: - case BOOLEAN_TYPE: - case CHAR_TYPE: - return 1; - - case SET_TYPE: - case ARRAY_TYPE: - case RECORD_TYPE: - case UNION_TYPE: - case QUAL_UNION_TYPE: - case ENUMERAL_TYPE: - case FUNCTION_TYPE: - case METHOD_TYPE: - case POINTER_TYPE: - case REFERENCE_TYPE: - case FILE_TYPE: - case OFFSET_TYPE: - case LANG_TYPE: - case VECTOR_TYPE: - return 0; - - default: - abort (); - } - return 0; -} - -/* Given a pointer to some ..._DECL tree node, generate an assembly language - equate directive which will associate a symbolic name with the current DIE. - - The name used is an artificial label generated from the DECL_UID number - associated with the given decl node. The name it gets equated to is the - symbolic label that we (previously) output at the start of the DIE that - we are currently generating. - - Calling this function while generating some "decl related" form of DIE - makes it possible to later refer to the DIE which represents the given - decl simply by re-generating the symbolic name from the ..._DECL node's - UID number. */ - -static void -equate_decl_number_to_die_number (decl) - tree decl; -{ - /* In the case where we are generating a DIE for some ..._DECL node - which represents either some inline function declaration or some - entity declared within an inline function declaration/definition, - setup a symbolic name for the current DIE so that we have a name - for this DIE that we can easily refer to later on within - AT_abstract_origin attributes. */ - - char decl_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl)); - sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); - ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label); -} - -/* Given a pointer to some ..._TYPE tree node, generate an assembly language - equate directive which will associate a symbolic name with the current DIE. - - The name used is an artificial label generated from the TYPE_UID number - associated with the given type node. The name it gets equated to is the - symbolic label that we (previously) output at the start of the DIE that - we are currently generating. - - Calling this function while generating some "type related" form of DIE - makes it easy to later refer to the DIE which represents the given type - simply by re-generating the alternative name from the ..._TYPE node's - UID number. */ - -static inline void -equate_type_number_to_die_number (type) - tree type; -{ - char type_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - /* We are generating a DIE to represent the main variant of this type - (i.e the type without any const or volatile qualifiers) so in order - to get the equate to come out right, we need to get the main variant - itself here. */ - - type = type_main_variant (type); - - sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type)); - sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); - ASM_OUTPUT_DEF (asm_out_file, type_label, die_label); -} - -static void -output_reg_number (rtl) - rtx rtl; -{ - unsigned regno = REGNO (rtl); - - if (regno >= DWARF_FRAME_REGISTERS) - { - warning_with_decl (dwarf_last_decl, - "internal regno botch: `%s' has regno = %d\n", - regno); - regno = 0; - } - dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno))); - if (flag_debug_asm) - { - fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START); - PRINT_REG (rtl, 0, asm_out_file); - } - fputc ('\n', asm_out_file); -} - -/* The following routine is a nice and simple transducer. It converts the - RTL for a variable or parameter (resident in memory) into an equivalent - Dwarf representation of a mechanism for getting the address of that same - variable onto the top of a hypothetical "address evaluation" stack. - - When creating memory location descriptors, we are effectively trans- - forming the RTL for a memory-resident object into its Dwarf postfix - expression equivalent. This routine just recursively descends an - RTL tree, turning it into Dwarf postfix code as it goes. */ - -static void -output_mem_loc_descriptor (rtl) - rtx rtl; -{ - /* Note that for a dynamically sized array, the location we will - generate a description of here will be the lowest numbered location - which is actually within the array. That's *not* necessarily the - same as the zeroth element of the array. */ - -#ifdef ASM_SIMPLIFY_DWARF_ADDR - rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); -#endif - - switch (GET_CODE (rtl)) - { - case SUBREG: - - /* The case of a subreg may arise when we have a local (register) - variable or a formal (register) parameter which doesn't quite - fill up an entire register. For now, just assume that it is - legitimate to make the Dwarf info refer to the whole register - which contains the given subreg. */ - - rtl = SUBREG_REG (rtl); - /* Drop thru. */ - - case REG: - - /* Whenever a register number forms a part of the description of - the method for calculating the (dynamic) address of a memory - resident object, DWARF rules require the register number to - be referred to as a "base register". This distinction is not - based in any way upon what category of register the hardware - believes the given register belongs to. This is strictly - DWARF terminology we're dealing with here. - - Note that in cases where the location of a memory-resident data - object could be expressed as: - - OP_ADD (OP_BASEREG (basereg), OP_CONST (0)) - - the actual DWARF location descriptor that we generate may just - be OP_BASEREG (basereg). This may look deceptively like the - object in question was allocated to a register (rather than - in memory) so DWARF consumers need to be aware of the subtle - distinction between OP_REG and OP_BASEREG. */ - - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG); - output_reg_number (rtl); - break; - - case MEM: - output_mem_loc_descriptor (XEXP (rtl, 0)); - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4); - break; - - case CONST: - case SYMBOL_REF: - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR); - ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); - break; - - case PLUS: - output_mem_loc_descriptor (XEXP (rtl, 0)); - output_mem_loc_descriptor (XEXP (rtl, 1)); - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); - break; - - case CONST_INT: - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl)); - break; - - case MULT: - /* If a pseudo-reg is optimized away, it is possible for it to - be replaced with a MEM containing a multiply. Use a GNU extension - to describe it. */ - output_mem_loc_descriptor (XEXP (rtl, 0)); - output_mem_loc_descriptor (XEXP (rtl, 1)); - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT); - break; - - default: - abort (); - } -} - -/* Output a proper Dwarf location descriptor for a variable or parameter - which is either allocated in a register or in a memory location. For - a register, we just generate an OP_REG and the register number. For a - memory location we provide a Dwarf postfix expression describing how to - generate the (dynamic) address of the object onto the address stack. */ - -static void -output_loc_descriptor (rtl) - rtx rtl; -{ - switch (GET_CODE (rtl)) - { - case SUBREG: - - /* The case of a subreg may arise when we have a local (register) - variable or a formal (register) parameter which doesn't quite - fill up an entire register. For now, just assume that it is - legitimate to make the Dwarf info refer to the whole register - which contains the given subreg. */ - - rtl = SUBREG_REG (rtl); - /* Drop thru. */ - - case REG: - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG); - output_reg_number (rtl); - break; - - case MEM: - output_mem_loc_descriptor (XEXP (rtl, 0)); - break; - - default: - abort (); /* Should never happen */ - } -} - -/* Given a tree node describing an array bound (either lower or upper) - output a representation for that bound. */ - -static void -output_bound_representation (bound, dim_num, u_or_l) - tree bound; - unsigned dim_num; /* For multi-dimensional arrays. */ - char u_or_l; /* Designates upper or lower bound. */ -{ - switch (TREE_CODE (bound)) - { - - case ERROR_MARK: - return; - - /* All fixed-bounds are represented by INTEGER_CST nodes. */ - - case INTEGER_CST: - if (host_integerp (bound, 0)) - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0)); - break; - - default: - - /* Dynamic bounds may be represented by NOP_EXPR nodes containing - SAVE_EXPR nodes, in which case we can do something, or as - an expression, which we cannot represent. */ - { - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (begin_label, BOUND_BEGIN_LABEL_FMT, - current_dienum, dim_num, u_or_l); - - sprintf (end_label, BOUND_END_LABEL_FMT, - current_dienum, dim_num, u_or_l); - - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - /* If optimization is turned on, the SAVE_EXPRs that describe - how to access the upper bound values are essentially bogus. - They only describe (at best) how to get at these values at - the points in the generated code right after they have just - been computed. Worse yet, in the typical case, the upper - bound values will not even *be* computed in the optimized - code, so these SAVE_EXPRs are entirely bogus. - - In order to compensate for this fact, we check here to see - if optimization is enabled, and if so, we effectively create - an empty location description for the (unknown and unknowable) - upper bound. - - This should not cause too much trouble for existing (stupid?) - debuggers because they have to deal with empty upper bounds - location descriptions anyway in order to be able to deal with - incomplete array types. - - Of course an intelligent debugger (GDB?) should be able to - comprehend that a missing upper bound specification in a - array type used for a storage class `auto' local array variable - indicates that the upper bound is both unknown (at compile- - time) and unknowable (at run-time) due to optimization. */ - - if (! optimize) - { - while (TREE_CODE (bound) == NOP_EXPR - || TREE_CODE (bound) == CONVERT_EXPR) - bound = TREE_OPERAND (bound, 0); - - if (TREE_CODE (bound) == SAVE_EXPR - && SAVE_EXPR_RTL (bound)) - output_loc_descriptor - (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX)); - } - - ASM_OUTPUT_LABEL (asm_out_file, end_label); - } - break; - - } -} - -/* Recursive function to output a sequence of value/name pairs for - enumeration constants in reversed order. This is called from - enumeration_type_die. */ - -static void -output_enumeral_list (link) - tree link; -{ - if (link) - { - output_enumeral_list (TREE_CHAIN (link)); - - if (host_integerp (TREE_VALUE (link), 0)) - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, - tree_low_cst (TREE_VALUE (link), 0)); - - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, - IDENTIFIER_POINTER (TREE_PURPOSE (link))); - } -} - -/* Given an unsigned value, round it up to the lowest multiple of `boundary' - which is not less than the value itself. */ - -static inline HOST_WIDE_INT -ceiling (value, boundary) - HOST_WIDE_INT value; - unsigned int boundary; -{ - return (((value + boundary - 1) / boundary) * boundary); -} - -/* Given a pointer to what is assumed to be a FIELD_DECL node, return a - pointer to the declared type for the relevant field variable, or return - `integer_type_node' if the given node turns out to be an ERROR_MARK node. */ - -static inline tree -field_type (decl) - tree decl; -{ - tree type; - - if (TREE_CODE (decl) == ERROR_MARK) - return integer_type_node; - - type = DECL_BIT_FIELD_TYPE (decl); - if (type == NULL) - type = TREE_TYPE (decl); - return type; -} - -/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE - node, return the alignment in bits for the type, or else return - BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */ - -static inline unsigned int -simple_type_align_in_bits (type) - tree type; -{ - return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; -} - -/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE - node, return the size in bits for the type if it is a constant, or - else return the alignment for the type if the type's size is not - constant, or else return BITS_PER_WORD if the type actually turns out - to be an ERROR_MARK node. */ - -static inline unsigned HOST_WIDE_INT -simple_type_size_in_bits (type) - tree type; -{ - tree type_size_tree; - - if (TREE_CODE (type) == ERROR_MARK) - return BITS_PER_WORD; - type_size_tree = TYPE_SIZE (type); - - if (type_size_tree == NULL_TREE) - return 0; - if (! host_integerp (type_size_tree, 1)) - return TYPE_ALIGN (type); - return tree_low_cst (type_size_tree, 1); -} - -/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and - return the byte offset of the lowest addressed byte of the "containing - object" for the given FIELD_DECL, or return 0 if we are unable to deter- - mine what that offset is, either because the argument turns out to be a - pointer to an ERROR_MARK node, or because the offset is actually variable. - (We can't handle the latter case just yet.) */ - -static HOST_WIDE_INT -field_byte_offset (decl) - tree decl; -{ - unsigned int type_align_in_bytes; - unsigned int type_align_in_bits; - unsigned HOST_WIDE_INT type_size_in_bits; - HOST_WIDE_INT object_offset_in_align_units; - HOST_WIDE_INT object_offset_in_bits; - HOST_WIDE_INT object_offset_in_bytes; - tree type; - tree field_size_tree; - HOST_WIDE_INT bitpos_int; - HOST_WIDE_INT deepest_bitpos; - unsigned HOST_WIDE_INT field_size_in_bits; - - if (TREE_CODE (decl) == ERROR_MARK) - return 0; - - if (TREE_CODE (decl) != FIELD_DECL) - abort (); - - type = field_type (decl); - field_size_tree = DECL_SIZE (decl); - - /* The size could be unspecified if there was an error, or for - a flexible array member. */ - if (! field_size_tree) - field_size_tree = bitsize_zero_node; - - /* We cannot yet cope with fields whose positions or sizes are variable, - so for now, when we see such things, we simply return 0. Someday, - we may be able to handle such cases, but it will be damn difficult. */ - - if (! host_integerp (bit_position (decl), 0) - || ! host_integerp (field_size_tree, 1)) - return 0; - - bitpos_int = int_bit_position (decl); - field_size_in_bits = tree_low_cst (field_size_tree, 1); - - type_size_in_bits = simple_type_size_in_bits (type); - type_align_in_bits = simple_type_align_in_bits (type); - type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; - - /* Note that the GCC front-end doesn't make any attempt to keep track - of the starting bit offset (relative to the start of the containing - structure type) of the hypothetical "containing object" for a bit- - field. Thus, when computing the byte offset value for the start of - the "containing object" of a bit-field, we must deduce this infor- - mation on our own. - - This can be rather tricky to do in some cases. For example, handling - the following structure type definition when compiling for an i386/i486 - target (which only aligns long long's to 32-bit boundaries) can be very - tricky: - - struct S { - int field1; - long long field2:31; - }; - - Fortunately, there is a simple rule-of-thumb which can be used in such - cases. When compiling for an i386/i486, GCC will allocate 8 bytes for - the structure shown above. It decides to do this based upon one simple - rule for bit-field allocation. Quite simply, GCC allocates each "con- - taining object" for each bit-field at the first (i.e. lowest addressed) - legitimate alignment boundary (based upon the required minimum alignment - for the declared type of the field) which it can possibly use, subject - to the condition that there is still enough available space remaining - in the containing object (when allocated at the selected point) to - fully accommodate all of the bits of the bit-field itself. - - This simple rule makes it obvious why GCC allocates 8 bytes for each - object of the structure type shown above. When looking for a place to - allocate the "containing object" for `field2', the compiler simply tries - to allocate a 64-bit "containing object" at each successive 32-bit - boundary (starting at zero) until it finds a place to allocate that 64- - bit field such that at least 31 contiguous (and previously unallocated) - bits remain within that selected 64 bit field. (As it turns out, for - the example above, the compiler finds that it is OK to allocate the - "containing object" 64-bit field at bit-offset zero within the - structure type.) - - Here we attempt to work backwards from the limited set of facts we're - given, and we try to deduce from those facts, where GCC must have - believed that the containing object started (within the structure type). - - The value we deduce is then used (by the callers of this routine) to - generate AT_location and AT_bit_offset attributes for fields (both - bit-fields and, in the case of AT_location, regular fields as well). */ - - /* Figure out the bit-distance from the start of the structure to the - "deepest" bit of the bit-field. */ - deepest_bitpos = bitpos_int + field_size_in_bits; - - /* This is the tricky part. Use some fancy footwork to deduce where the - lowest addressed bit of the containing object must be. */ - object_offset_in_bits - = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; - - /* Compute the offset of the containing object in "alignment units". */ - object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; - - /* Compute the offset of the containing object in bytes. */ - object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; - - /* The above code assumes that the field does not cross an alignment - boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined, - or if the structure is packed. If this happens, then we get an object - which starts after the bitfield, which means that the bit offset is - negative. Gdb fails when given negative bit offsets. We avoid this - by recomputing using the first bit of the bitfield. This will give - us an object which does not completely contain the bitfield, but it - will be aligned, and it will contain the first bit of the bitfield. - - However, only do this for a BYTES_BIG_ENDIAN target. For a - ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first - first bit of the bitfield. If we recompute using bitpos_int + 1 below, - then we end up computing the object byte offset for the wrong word of the - desired bitfield, which in turn causes the field offset to be negative - in bit_offset_attribute. */ - if (BYTES_BIG_ENDIAN - && object_offset_in_bits > bitpos_int) - { - deepest_bitpos = bitpos_int + 1; - object_offset_in_bits - = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; - object_offset_in_align_units = (object_offset_in_bits - / type_align_in_bits); - object_offset_in_bytes = (object_offset_in_align_units - * type_align_in_bytes); - } - - return object_offset_in_bytes; -} - -/****************************** attributes *********************************/ - -/* The following routines are responsible for writing out the various types - of Dwarf attributes (and any following data bytes associated with them). - These routines are listed in order based on the numerical codes of their - associated attributes. */ - -/* Generate an AT_sibling attribute. */ - -static inline void -sibling_attribute () -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling); - sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); - ASM_OUTPUT_DWARF_REF (asm_out_file, label); -} - -/* Output the form of location attributes suitable for whole variables and - whole parameters. Note that the location attributes for struct fields - are generated by the routine `data_member_location_attribute' below. */ - -static void -location_attribute (rtl) - rtx rtl; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); - sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - /* Handle a special case. If we are about to output a location descriptor - for a variable or parameter which has been optimized out of existence, - don't do that. Instead we output a zero-length location descriptor - value as part of the location attribute. - - A variable which has been optimized out of existence will have a - DECL_RTL value which denotes a pseudo-reg. - - Currently, in some rare cases, variables can have DECL_RTL values - which look like (MEM (REG pseudo-reg#)). These cases are due to - bugs elsewhere in the compiler. We treat such cases - as if the variable(s) in question had been optimized out of existence. - - Note that in all cases where we wish to express the fact that a - variable has been optimized out of existence, we do not simply - suppress the generation of the entire location attribute because - the absence of a location attribute in certain kinds of DIEs is - used to indicate something else entirely... i.e. that the DIE - represents an object declaration, but not a definition. So saith - the PLSIG. - */ - - if (! is_pseudo_reg (rtl) - && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0)))) - output_loc_descriptor (rtl); - - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -/* Output the specialized form of location attribute used for data members - of struct and union types. - - In the special case of a FIELD_DECL node which represents a bit-field, - the "offset" part of this special location descriptor must indicate the - distance in bytes from the lowest-addressed byte of the containing - struct or union type to the lowest-addressed byte of the "containing - object" for the bit-field. (See the `field_byte_offset' function above.) - - For any given bit-field, the "containing object" is a hypothetical - object (of some integral or enum type) within which the given bit-field - lives. The type of this hypothetical "containing object" is always the - same as the declared type of the individual bit-field itself (for GCC - anyway... the DWARF spec doesn't actually mandate this). - - Note that it is the size (in bytes) of the hypothetical "containing - object" which will be given in the AT_byte_size attribute for this - bit-field. (See the `byte_size_attribute' function below.) It is - also used when calculating the value of the AT_bit_offset attribute. - (See the `bit_offset_attribute' function below.) */ - -static void -data_member_location_attribute (t) - tree t; -{ - unsigned object_offset_in_bytes; - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - if (TREE_CODE (t) == TREE_VEC) - object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0); - else - object_offset_in_bytes = field_byte_offset (t); - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); - sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes); - ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -/* Output an AT_const_value attribute for a variable or a parameter which - does not have a "location" either in memory or in a register. These - things can arise in GNU C when a constant is passed as an actual - parameter to an inlined function. They can also arise in C++ where - declared constants do not necessarily get memory "homes". */ - -static void -const_value_attribute (rtl) - rtx rtl; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4); - sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - switch (GET_CODE (rtl)) - { - case CONST_INT: - /* Note that a CONST_INT rtx could represent either an integer or - a floating-point constant. A CONST_INT is used whenever the - constant will fit into a single word. In all such cases, the - original mode of the constant value is wiped out, and the - CONST_INT rtx is assigned VOIDmode. Since we no longer have - precise mode information for these constants, we always just - output them using 4 bytes. */ - - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl)); - break; - - case CONST_DOUBLE: - /* Note that a CONST_DOUBLE rtx could represent either an integer - or a floating-point constant. A CONST_DOUBLE is used whenever - the constant requires more than one word in order to be adequately - represented. In all such cases, the original mode of the constant - value is preserved as the mode of the CONST_DOUBLE rtx, but for - simplicity we always just output CONST_DOUBLEs using 8 bytes. */ - - ASM_OUTPUT_DWARF_DATA8 (asm_out_file, - (unsigned int) CONST_DOUBLE_HIGH (rtl), - (unsigned int) CONST_DOUBLE_LOW (rtl)); - break; - - case CONST_STRING: - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0)); - break; - - case SYMBOL_REF: - case LABEL_REF: - case CONST: - ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); - break; - - case PLUS: - /* In cases where an inlined instance of an inline function is passed - the address of an `auto' variable (which is local to the caller) - we can get a situation where the DECL_RTL of the artificial - local variable (for the inlining) which acts as a stand-in for - the corresponding formal parameter (of the inline function) - will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). - This is not exactly a compile-time constant expression, but it - isn't the address of the (artificial) local variable either. - Rather, it represents the *value* which the artificial local - variable always has during its lifetime. We currently have no - way to represent such quasi-constant values in Dwarf, so for now - we just punt and generate an AT_const_value attribute with form - FORM_BLOCK4 and a length of zero. */ - break; - - default: - abort (); /* No other kinds of rtx should be possible here. */ - } - - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -/* Generate *either* an AT_location attribute or else an AT_const_value - data attribute for a variable or a parameter. We generate the - AT_const_value attribute only in those cases where the given - variable or parameter does not have a true "location" either in - memory or in a register. This can happen (for example) when a - constant is passed as an actual argument in a call to an inline - function. (It's possible that these things can crop up in other - ways also.) Note that one type of constant value which can be - passed into an inlined function is a constant pointer. This can - happen for example if an actual argument in an inlined function - call evaluates to a compile-time constant address. */ - -static void -location_or_const_value_attribute (decl) - tree decl; -{ - rtx rtl; - - if (TREE_CODE (decl) == ERROR_MARK) - return; - - if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL)) - { - /* Should never happen. */ - abort (); - return; - } - - /* Here we have to decide where we are going to say the parameter "lives" - (as far as the debugger is concerned). We only have a couple of choices. - GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL - normally indicates where the parameter lives during most of the activa- - tion of the function. If optimization is enabled however, this could - be either NULL or else a pseudo-reg. Both of those cases indicate that - the parameter doesn't really live anywhere (as far as the code generation - parts of GCC are concerned) during most of the function's activation. - That will happen (for example) if the parameter is never referenced - within the function. - - We could just generate a location descriptor here for all non-NULL - non-pseudo values of DECL_RTL and ignore all of the rest, but we can - be a little nicer than that if we also consider DECL_INCOMING_RTL in - cases where DECL_RTL is NULL or is a pseudo-reg. - - Note however that we can only get away with using DECL_INCOMING_RTL as - a backup substitute for DECL_RTL in certain limited cases. In cases - where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl) - we can be sure that the parameter was passed using the same type as it - is declared to have within the function, and that its DECL_INCOMING_RTL - points us to a place where a value of that type is passed. In cases - where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types - however, we cannot (in general) use DECL_INCOMING_RTL as a backup - substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL - points us to a value of some type which is *different* from the type - of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL - to generate a location attribute in such cases, the debugger would - end up (for example) trying to fetch a `float' from a place which - actually contains the first part of a `double'. That would lead to - really incorrect and confusing output at debug-time, and we don't - want that now do we? - - So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL - in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a - couple of cute exceptions however. On little-endian machines we can - get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is - not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is - an integral type which is smaller than TREE_TYPE(decl). These cases - arise when (on a little-endian machine) a non-prototyped function has - a parameter declared to be of type `short' or `char'. In such cases, - TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be - `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the - passed `int' value. If the debugger then uses that address to fetch a - `short' or a `char' (on a little-endian machine) the result will be the - correct data, so we allow for such exceptional cases below. - - Note that our goal here is to describe the place where the given formal - parameter lives during most of the function's activation (i.e. between - the end of the prologue and the start of the epilogue). We'll do that - as best as we can. Note however that if the given formal parameter is - modified sometime during the execution of the function, then a stack - backtrace (at debug-time) will show the function as having been called - with the *new* value rather than the value which was originally passed - in. This happens rarely enough that it is not a major problem, but it - *is* a problem, and I'd like to fix it. A future version of dwarfout.c - may generate two additional attributes for any given TAG_formal_parameter - DIE which will describe the "passed type" and the "passed location" for - the given formal parameter in addition to the attributes we now generate - to indicate the "declared type" and the "active location" for each - parameter. This additional set of attributes could be used by debuggers - for stack backtraces. - - Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL - can be NULL also. This happens (for example) for inlined-instances of - inline function formal parameters which are never referenced. This really - shouldn't be happening. All PARM_DECL nodes should get valid non-NULL - DECL_INCOMING_RTL values, but integrate.c doesn't currently generate - these values for inlined instances of inline function parameters, so - when we see such cases, we are just out-of-luck for the time - being (until integrate.c gets fixed). - */ - - /* Use DECL_RTL as the "location" unless we find something better. */ - rtl = DECL_RTL (decl); - - if (TREE_CODE (decl) == PARM_DECL) - if (rtl == NULL_RTX || is_pseudo_reg (rtl)) - { - /* This decl represents a formal parameter which was optimized out. */ - tree declared_type = type_main_variant (TREE_TYPE (decl)); - tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); - - /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle - *all* cases where (rtl == NULL_RTX) just below. */ - - if (declared_type == passed_type) - rtl = DECL_INCOMING_RTL (decl); - else if (! BYTES_BIG_ENDIAN) - if (TREE_CODE (declared_type) == INTEGER_TYPE) - /* NMS WTF? */ - if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) - rtl = DECL_INCOMING_RTL (decl); - } - - if (rtl == NULL_RTX) - return; - - rtl = eliminate_regs (rtl, 0, NULL_RTX); -#ifdef LEAF_REG_REMAP - if (current_function_uses_only_leaf_regs) - leaf_renumber_regs_insn (rtl); -#endif - - switch (GET_CODE (rtl)) - { - case ADDRESSOF: - /* The address of a variable that was optimized away; don't emit - anything. */ - break; - - case CONST_INT: - case CONST_DOUBLE: - case CONST_STRING: - case SYMBOL_REF: - case LABEL_REF: - case CONST: - case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ - const_value_attribute (rtl); - break; - - case MEM: - case REG: - case SUBREG: - location_attribute (rtl); - break; - - case CONCAT: - /* ??? CONCAT is used for complex variables, which may have the real - part stored in one place and the imag part stored somewhere else. - DWARF1 has no way to describe a variable that lives in two different - places, so we just describe where the first part lives, and hope that - the second part is stored after it. */ - location_attribute (XEXP (rtl, 0)); - break; - - default: - abort (); /* Should never happen. */ - } -} - -/* Generate an AT_name attribute given some string value to be included as - the value of the attribute. */ - -static inline void -name_attribute (name_string) - const char *name_string; -{ - if (name_string && *name_string) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string); - } -} - -static inline void -fund_type_attribute (ft_code) - unsigned ft_code; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type); - ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code); -} - -static void -mod_fund_type_attribute (type, decl_const, decl_volatile) - tree type; - int decl_const; - int decl_volatile; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type); - sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, MT_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - write_modifier_bytes (type, decl_const, decl_volatile); - ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, - fundamental_type_code (root_type (type))); - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -static inline void -user_def_type_attribute (type) - tree type; -{ - char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type); - sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type)); - ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); -} - -static void -mod_u_d_type_attribute (type, decl_const, decl_volatile) - tree type; - int decl_const; - int decl_volatile; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type); - sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, MT_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - write_modifier_bytes (type, decl_const, decl_volatile); - sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type))); - ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -#ifdef USE_ORDERING_ATTRIBUTE -static inline void -ordering_attribute (ordering) - unsigned ordering; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering); - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering); -} -#endif /* defined(USE_ORDERING_ATTRIBUTE) */ - -/* Note that the block of subscript information for an array type also - includes information about the element type of type given array type. */ - -static void -subscript_data_attribute (type) - tree type; -{ - unsigned dimension_number; - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data); - sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, SS_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - /* The GNU compilers represent multidimensional array types as sequences - of one dimensional array types whose element types are themselves array - types. Here we squish that down, so that each multidimensional array - type gets only one array_type DIE in the Dwarf debugging info. The - draft Dwarf specification say that we are allowed to do this kind - of compression in C (because there is no difference between an - array or arrays and a multidimensional array in C) but for other - source languages (e.g. Ada) we probably shouldn't do this. */ - - for (dimension_number = 0; - TREE_CODE (type) == ARRAY_TYPE; - type = TREE_TYPE (type), dimension_number++) - { - tree domain = TYPE_DOMAIN (type); - - /* Arrays come in three flavors. Unspecified bounds, fixed - bounds, and (in GNU C only) variable bounds. Handle all - three forms here. */ - - if (domain) - { - /* We have an array type with specified bounds. */ - - tree lower = TYPE_MIN_VALUE (domain); - tree upper = TYPE_MAX_VALUE (domain); - - /* Handle only fundamental types as index types for now. */ - if (! type_is_fundamental (domain)) - abort (); - - /* Output the representation format byte for this dimension. */ - ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, - FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST, - upper && TREE_CODE (upper) == INTEGER_CST)); - - /* Output the index type for this dimension. */ - ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, - fundamental_type_code (domain)); - - /* Output the representation for the lower bound. */ - output_bound_representation (lower, dimension_number, 'l'); - - /* Output the representation for the upper bound. */ - if (upper) - output_bound_representation (upper, dimension_number, 'u'); - else - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); - } - else - { - /* We have an array type with an unspecified length. For C and - C++ we can assume that this really means that (a) the index - type is an integral type, and (b) the lower bound is zero. - Note that Dwarf defines the representation of an unspecified - (upper) bound as being a zero-length location description. */ - - /* Output the array-bounds format byte. */ - - ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X); - - /* Output the (assumed) index type. */ - - ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer); - - /* Output the (assumed) lower bound (constant) value. */ - - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); - - /* Output the (empty) location description for the upper bound. */ - - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); - } - } - - /* Output the prefix byte that says that the element type is coming up. */ - - ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET); - - /* Output a representation of the type of the elements of this array type. */ - - type_attribute (type, 0, 0); - - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -static void -byte_size_attribute (tree_node) - tree tree_node; -{ - unsigned size; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size); - switch (TREE_CODE (tree_node)) - { - case ERROR_MARK: - size = 0; - break; - - case ENUMERAL_TYPE: - case RECORD_TYPE: - case UNION_TYPE: - case QUAL_UNION_TYPE: - case ARRAY_TYPE: - size = int_size_in_bytes (tree_node); - break; - - case FIELD_DECL: - /* For a data member of a struct or union, the AT_byte_size is - generally given as the number of bytes normally allocated for - an object of the *declared* type of the member itself. This - is true even for bit-fields. */ - size = simple_type_size_in_bits (field_type (tree_node)) - / BITS_PER_UNIT; - break; - - default: - abort (); - } - - /* Note that `size' might be -1 when we get to this point. If it - is, that indicates that the byte size of the entity in question - is variable. We have no good way of expressing this fact in Dwarf - at the present time, so just let the -1 pass on through. */ - - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size); -} - -/* For a FIELD_DECL node which represents a bit-field, output an attribute - which specifies the distance in bits from the highest order bit of the - "containing object" for the bit-field to the highest order bit of the - bit-field itself. - - For any given bit-field, the "containing object" is a hypothetical - object (of some integral or enum type) within which the given bit-field - lives. The type of this hypothetical "containing object" is always the - same as the declared type of the individual bit-field itself. - - The determination of the exact location of the "containing object" for - a bit-field is rather complicated. It's handled by the `field_byte_offset' - function (above). - - Note that it is the size (in bytes) of the hypothetical "containing - object" which will be given in the AT_byte_size attribute for this - bit-field. (See `byte_size_attribute' above.) */ - -static inline void -bit_offset_attribute (decl) - tree decl; -{ - HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); - tree type = DECL_BIT_FIELD_TYPE (decl); - HOST_WIDE_INT bitpos_int; - HOST_WIDE_INT highest_order_object_bit_offset; - HOST_WIDE_INT highest_order_field_bit_offset; - HOST_WIDE_INT bit_offset; - - /* Must be a bit field. */ - if (!type - || TREE_CODE (decl) != FIELD_DECL) - abort (); - - /* We can't yet handle bit-fields whose offsets or sizes are variable, so - if we encounter such things, just return without generating any - attribute whatsoever. */ - - if (! host_integerp (bit_position (decl), 0) - || ! host_integerp (DECL_SIZE (decl), 1)) - return; - - bitpos_int = int_bit_position (decl); - - /* Note that the bit offset is always the distance (in bits) from the - highest-order bit of the "containing object" to the highest-order - bit of the bit-field itself. Since the "high-order end" of any - object or field is different on big-endian and little-endian machines, - the computation below must take account of these differences. */ - - highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; - highest_order_field_bit_offset = bitpos_int; - - if (! BYTES_BIG_ENDIAN) - { - highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1); - highest_order_object_bit_offset += simple_type_size_in_bits (type); - } - - bit_offset = - (! BYTES_BIG_ENDIAN - ? highest_order_object_bit_offset - highest_order_field_bit_offset - : highest_order_field_bit_offset - highest_order_object_bit_offset); - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset); - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset); -} - -/* For a FIELD_DECL node which represents a bit field, output an attribute - which specifies the length in bits of the given field. */ - -static inline void -bit_size_attribute (decl) - tree decl; -{ - /* Must be a field and a bit field. */ - if (TREE_CODE (decl) != FIELD_DECL - || ! DECL_BIT_FIELD_TYPE (decl)) - abort (); - - if (host_integerp (DECL_SIZE (decl), 1)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, - tree_low_cst (DECL_SIZE (decl), 1)); - } -} - -/* The following routine outputs the `element_list' attribute for enumeration - type DIEs. The element_lits attribute includes the names and values of - all of the enumeration constants associated with the given enumeration - type. */ - -static inline void -element_list_attribute (element) - tree element; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list); - sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, EE_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - /* Here we output a list of value/name pairs for each enumeration constant - defined for this enumeration type (as required), but we do it in REVERSE - order. The order is the one required by the draft #5 Dwarf specification - published by the UI/PLSIG. */ - - output_enumeral_list (element); /* Recursively output the whole list. */ - - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -/* Generate an AT_stmt_list attribute. These are normally present only in - DIEs with a TAG_compile_unit tag. */ - -static inline void -stmt_list_attribute (label) - const char *label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list); - /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ - ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); -} - -/* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or - for a subroutine DIE. */ - -static inline void -low_pc_attribute (asm_low_label) - const char *asm_low_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label); -} - -/* Generate an AT_high_pc attribute for a lexical_block DIE or for a - subroutine DIE. */ - -static inline void -high_pc_attribute (asm_high_label) - const char *asm_high_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label); -} - -/* Generate an AT_body_begin attribute for a subroutine DIE. */ - -static inline void -body_begin_attribute (asm_begin_label) - const char *asm_begin_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label); -} - -/* Generate an AT_body_end attribute for a subroutine DIE. */ - -static inline void -body_end_attribute (asm_end_label) - const char *asm_end_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label); -} - -/* Generate an AT_language attribute given a LANG value. These attributes - are used only within TAG_compile_unit DIEs. */ - -static inline void -language_attribute (language_code) - unsigned language_code; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code); -} - -static inline void -member_attribute (context) - tree context; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - /* Generate this attribute only for members in C++. */ - - if (context != NULL && is_tagged_type (context)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member); - sprintf (label, TYPE_NAME_FMT, TYPE_UID (context)); - ASM_OUTPUT_DWARF_REF (asm_out_file, label); - } -} - -#if 0 -#ifndef SL_BEGIN_LABEL_FMT -#define SL_BEGIN_LABEL_FMT "*.L_sl%u" -#endif -#ifndef SL_END_LABEL_FMT -#define SL_END_LABEL_FMT "*.L_sl%u_e" -#endif - -static inline void -string_length_attribute (upper_bound) - tree upper_bound; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length); - sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, SL_END_LABEL_FMT, current_dienum); - ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - output_bound_representation (upper_bound, 0, 'u'); - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} -#endif - -static inline void -comp_dir_attribute (dirname) - const char *dirname; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname); -} - -static inline void -sf_names_attribute (sf_names_start_label) - const char *sf_names_start_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names); - /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ - ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label); -} - -static inline void -src_info_attribute (src_info_start_label) - const char *src_info_start_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info); - /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ - ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label); -} - -static inline void -mac_info_attribute (mac_info_start_label) - const char *mac_info_start_label; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info); - /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ - ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label); -} - -static inline void -prototyped_attribute (func_type) - tree func_type; -{ - if ((strcmp (lang_hooks.name, "GNU C") == 0) - && (TYPE_ARG_TYPES (func_type) != NULL)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - } -} - -static inline void -producer_attribute (producer) - const char *producer; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer); -} - -static inline void -inline_attribute (decl) - tree decl; -{ - if (DECL_INLINE (decl)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - } -} - -static inline void -containing_type_attribute (containing_type) - tree containing_type; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type); - sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type)); - ASM_OUTPUT_DWARF_REF (asm_out_file, label); -} - -static inline void -abstract_origin_attribute (origin) - tree origin; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin); - switch (TREE_CODE_CLASS (TREE_CODE (origin))) - { - case 'd': - sprintf (label, DECL_NAME_FMT, DECL_UID (origin)); - break; - - case 't': - sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin)); - break; - - default: - abort (); /* Should never happen. */ - - } - ASM_OUTPUT_DWARF_REF (asm_out_file, label); -} - -#ifdef DWARF_DECL_COORDINATES -static inline void -src_coords_attribute (src_fileno, src_lineno) - unsigned src_fileno; - unsigned src_lineno; -{ - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords); - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno); - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno); -} -#endif /* defined(DWARF_DECL_COORDINATES) */ - -static inline void -pure_or_virtual_attribute (func_decl) - tree func_decl; -{ - if (DECL_VIRTUAL_P (func_decl)) - { -#if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */ - if (DECL_ABSTRACT_VIRTUAL_P (func_decl)) - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual); - else -#endif - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - } -} - -/************************* end of attributes *****************************/ - -/********************* utility routines for DIEs *************************/ - -/* Output an AT_name attribute and an AT_src_coords attribute for the - given decl, but only if it actually has a name. */ - -static void -name_and_src_coords_attributes (decl) - tree decl; -{ - tree decl_name = DECL_NAME (decl); - - if (decl_name && IDENTIFIER_POINTER (decl_name)) - { - name_attribute (IDENTIFIER_POINTER (decl_name)); -#ifdef DWARF_DECL_COORDINATES - { - register unsigned file_index; - - /* This is annoying, but we have to pop out of the .debug section - for a moment while we call `lookup_filename' because calling it - may cause a temporary switch into the .debug_sfnames section and - most svr4 assemblers are not smart enough to be able to nest - section switches to any depth greater than one. Note that we - also can't skirt this issue by delaying all output to the - .debug_sfnames section unit the end of compilation because that - would cause us to have inter-section forward references and - Fred Fish sez that m68k/svr4 assemblers botch those. */ - - ASM_OUTPUT_POP_SECTION (asm_out_file); - file_index = lookup_filename (DECL_SOURCE_FILE (decl)); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); - - src_coords_attribute (file_index, DECL_SOURCE_LINE (decl)); - } -#endif /* defined(DWARF_DECL_COORDINATES) */ - } -} - -/* Many forms of DIEs contain a "type description" part. The following - routine writes out these "type descriptor" parts. */ - -static void -type_attribute (type, decl_const, decl_volatile) - tree type; - int decl_const; - int decl_volatile; -{ - enum tree_code code = TREE_CODE (type); - int root_type_modified; - - if (code == ERROR_MARK) - return; - - /* Handle a special case. For functions whose return type is void, - we generate *no* type attribute. (Note that no object may have - type `void', so this only applies to function return types. */ - - if (code == VOID_TYPE) - return; - - /* If this is a subtype, find the underlying type. Eventually, - this should write out the appropriate subtype info. */ - while ((code == INTEGER_TYPE || code == REAL_TYPE) - && TREE_TYPE (type) != 0) - type = TREE_TYPE (type), code = TREE_CODE (type); - - root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE - || decl_const || decl_volatile - || TYPE_READONLY (type) || TYPE_VOLATILE (type)); - - if (type_is_fundamental (root_type (type))) - { - if (root_type_modified) - mod_fund_type_attribute (type, decl_const, decl_volatile); - else - fund_type_attribute (fundamental_type_code (type)); - } - else - { - if (root_type_modified) - mod_u_d_type_attribute (type, decl_const, decl_volatile); - else - /* We have to get the type_main_variant here (and pass that to the - `user_def_type_attribute' routine) because the ..._TYPE node we - have might simply be a *copy* of some original type node (where - the copy was created to help us keep track of typedef names) - and that copy might have a different TYPE_UID from the original - ..._TYPE node. (Note that when `equate_type_number_to_die_number' - is labeling a given type DIE for future reference, it always and - only creates labels for DIEs representing *main variants*, and it - never even knows about non-main-variants.) */ - user_def_type_attribute (type_main_variant (type)); - } -} - -/* Given a tree pointer to a struct, class, union, or enum type node, return - a pointer to the (string) tag name for the given type, or zero if the - type was declared without a tag. */ - -static const char * -type_tag (type) - tree type; -{ - const char *name = 0; - - if (TYPE_NAME (type) != 0) - { - tree t = 0; - - /* Find the IDENTIFIER_NODE for the type name. */ - if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) - t = TYPE_NAME (type); - - /* The g++ front end makes the TYPE_NAME of *each* tagged type point to - a TYPE_DECL node, regardless of whether or not a `typedef' was - involved. */ - else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL - && ! DECL_IGNORED_P (TYPE_NAME (type))) - t = DECL_NAME (TYPE_NAME (type)); - - /* Now get the name as a string, or invent one. */ - if (t != 0) - name = IDENTIFIER_POINTER (t); - } - - return (name == 0 || *name == '\0') ? 0 : name; -} - -static inline void -dienum_push () -{ - /* Start by checking if the pending_sibling_stack needs to be expanded. - If necessary, expand it. */ - - if (pending_siblings == pending_siblings_allocated) - { - pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT; - pending_sibling_stack - = (unsigned *) xrealloc (pending_sibling_stack, - pending_siblings_allocated * sizeof(unsigned)); - } - - pending_siblings++; - NEXT_DIE_NUM = next_unused_dienum++; -} - -/* Pop the sibling stack so that the most recently pushed DIEnum becomes the - NEXT_DIE_NUM. */ - -static inline void -dienum_pop () -{ - pending_siblings--; -} - -static inline tree -member_declared_type (member) - tree member; -{ - return (DECL_BIT_FIELD_TYPE (member)) - ? DECL_BIT_FIELD_TYPE (member) - : TREE_TYPE (member); -} - -/* Get the function's label, as described by its RTL. - This may be different from the DECL_NAME name used - in the source file. */ - -static const char * -function_start_label (decl) - tree decl; -{ - rtx x; - const char *fnname; - - x = DECL_RTL (decl); - if (GET_CODE (x) != MEM) - abort (); - x = XEXP (x, 0); - if (GET_CODE (x) != SYMBOL_REF) - abort (); - fnname = XSTR (x, 0); - return fnname; -} - - -/******************************* DIEs ************************************/ - -/* Output routines for individual types of DIEs. */ - -/* Note that every type of DIE (except a null DIE) gets a sibling. */ - -static void -output_array_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - member_attribute (TYPE_CONTEXT (type)); - - /* I believe that we can default the array ordering. SDB will probably - do the right things even if AT_ordering is not present. It's not - even an issue until we start to get into multidimensional arrays - anyway. If SDB is ever caught doing the Wrong Thing for multi- - dimensional arrays, then we'll have to put the AT_ordering attribute - back in. (But if and when we find out that we need to put these in, - we will only do so for multidimensional arrays. After all, we don't - want to waste space in the .debug section now do we?) */ - -#ifdef USE_ORDERING_ATTRIBUTE - ordering_attribute (ORD_row_major); -#endif /* defined(USE_ORDERING_ATTRIBUTE) */ - - subscript_data_attribute (type); -} - -static void -output_set_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - member_attribute (TYPE_CONTEXT (type)); - type_attribute (TREE_TYPE (type), 0, 0); -} - -#if 0 -/* Implement this when there is a GNU FORTRAN or GNU Ada front end. */ - -static void -output_entry_point_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point); - sibling_attribute (); - dienum_push (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - name_and_src_coords_attributes (decl); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0); - } - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); - else - low_pc_attribute (function_start_label (decl)); -} -#endif - -/* Output a DIE to represent an inlined instance of an enumeration type. */ - -static void -output_inlined_enumeration_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); - sibling_attribute (); - if (!TREE_ASM_WRITTEN (type)) - abort (); - abstract_origin_attribute (type); -} - -/* Output a DIE to represent an inlined instance of a structure type. */ - -static void -output_inlined_structure_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); - sibling_attribute (); - if (!TREE_ASM_WRITTEN (type)) - abort (); - abstract_origin_attribute (type); -} - -/* Output a DIE to represent an inlined instance of a union type. */ - -static void -output_inlined_union_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); - sibling_attribute (); - if (!TREE_ASM_WRITTEN (type)) - abort (); - abstract_origin_attribute (type); -} - -/* Output a DIE to represent an enumeration type. Note that these DIEs - include all of the information about the enumeration values also. - This information is encoded into the element_list attribute. */ - -static void -output_enumeration_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - name_attribute (type_tag (type)); - member_attribute (TYPE_CONTEXT (type)); - - /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the - given enum type is incomplete, do not generate the AT_byte_size - attribute or the AT_element_list attribute. */ - - if (COMPLETE_TYPE_P (type)) - { - byte_size_attribute (type); - element_list_attribute (TYPE_FIELDS (type)); - } -} - -/* Output a DIE to represent either a real live formal parameter decl or - to represent just the type of some formal parameter position in some - function type. - - Note that this routine is a bit unusual because its argument may be - a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which - represents an inlining of some PARM_DECL) or else some sort of a - ..._TYPE node. If it's the former then this function is being called - to output a DIE to represent a formal parameter object (or some inlining - thereof). If it's the latter, then this function is only being called - to output a TAG_formal_parameter DIE to stand as a placeholder for some - formal argument type of some subprogram type. */ - -static void -output_formal_parameter_die (arg) - void *arg; -{ - tree node = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter); - sibling_attribute (); - - switch (TREE_CODE_CLASS (TREE_CODE (node))) - { - case 'd': /* We were called with some kind of a ..._DECL node. */ - { - register tree origin = decl_ultimate_origin (node); - - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - name_and_src_coords_attributes (node); - type_attribute (TREE_TYPE (node), - TREE_READONLY (node), TREE_THIS_VOLATILE (node)); - } - if (DECL_ABSTRACT (node)) - equate_decl_number_to_die_number (node); - else - location_or_const_value_attribute (node); - } - break; - - case 't': /* We were called with some kind of a ..._TYPE node. */ - type_attribute (node, 0, 0); - break; - - default: - abort (); /* Should never happen. */ - } -} - -/* Output a DIE to represent a declared function (either file-scope - or block-local) which has "external linkage" (according to ANSI-C). */ - -static void -output_global_subroutine_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine); - sibling_attribute (); - dienum_push (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - tree type = TREE_TYPE (decl); - - name_and_src_coords_attributes (decl); - inline_attribute (decl); - prototyped_attribute (type); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (TREE_TYPE (type), 0, 0); - pure_or_virtual_attribute (decl); - } - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); - else - { - if (! DECL_EXTERNAL (decl) && ! in_class - && decl == current_function_decl) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - low_pc_attribute (function_start_label (decl)); - sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no); - high_pc_attribute (label); - if (use_gnu_debug_info_extensions) - { - sprintf (label, BODY_BEGIN_LABEL_FMT, - current_function_funcdef_no); - body_begin_attribute (label); - sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no); - body_end_attribute (label); - } - } - } -} - -/* Output a DIE to represent a declared data object (either file-scope - or block-local) which has "external linkage" (according to ANSI-C). */ - -static void -output_global_variable_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable); - sibling_attribute (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - name_and_src_coords_attributes (decl); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (TREE_TYPE (decl), - TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); - } - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); - else - { - if (! DECL_EXTERNAL (decl) && ! in_class - && current_function_decl == decl_function_context (decl)) - location_or_const_value_attribute (decl); - } -} - -static void -output_label_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label); - sibling_attribute (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - name_and_src_coords_attributes (decl); - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); - else - { - rtx insn = DECL_RTL (decl); - - /* Deleted labels are programmer specified labels which have been - eliminated because of various optimisations. We still emit them - here so that it is possible to put breakpoints on them. */ - if (GET_CODE (insn) == CODE_LABEL - || ((GET_CODE (insn) == NOTE - && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - /* When optimization is enabled (via -O) some parts of the compiler - (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which - represent source-level labels which were explicitly declared by - the user. This really shouldn't be happening though, so catch - it if it ever does happen. */ - - if (INSN_DELETED_P (insn)) - abort (); /* Should never happen. */ - - ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); - low_pc_attribute (label); - } - } -} - -static void -output_lexical_block_die (arg) - void *arg; -{ - tree stmt = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block); - sibling_attribute (); - dienum_push (); - if (! BLOCK_ABSTRACT (stmt)) - { - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt)); - low_pc_attribute (begin_label); - sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt)); - high_pc_attribute (end_label); - } -} - -static void -output_inlined_subroutine_die (arg) - void *arg; -{ - tree stmt = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine); - sibling_attribute (); - dienum_push (); - abstract_origin_attribute (block_ultimate_origin (stmt)); - if (! BLOCK_ABSTRACT (stmt)) - { - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt)); - low_pc_attribute (begin_label); - sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt)); - high_pc_attribute (end_label); - } -} - -/* Output a DIE to represent a declared data object (either file-scope - or block-local) which has "internal linkage" (according to ANSI-C). */ - -static void -output_local_variable_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable); - sibling_attribute (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - name_and_src_coords_attributes (decl); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (TREE_TYPE (decl), - TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); - } - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); - else - location_or_const_value_attribute (decl); -} - -static void -output_member_die (arg) - void *arg; -{ - tree decl = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member); - sibling_attribute (); - name_and_src_coords_attributes (decl); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (member_declared_type (decl), - TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); - if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */ - { - byte_size_attribute (decl); - bit_size_attribute (decl); - bit_offset_attribute (decl); - } - data_member_location_attribute (decl); -} - -#if 0 -/* Don't generate either pointer_type DIEs or reference_type DIEs. Use - modified types instead. - - We keep this code here just in case these types of DIEs may be - needed to represent certain things in other languages (e.g. Pascal) - someday. */ - -static void -output_pointer_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - member_attribute (TYPE_CONTEXT (type)); - type_attribute (TREE_TYPE (type), 0, 0); -} - -static void -output_reference_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - member_attribute (TYPE_CONTEXT (type)); - type_attribute (TREE_TYPE (type), 0, 0); -} -#endif - -static void -output_ptr_to_mbr_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - member_attribute (TYPE_CONTEXT (type)); - containing_type_attribute (TYPE_OFFSET_BASETYPE (type)); - type_attribute (TREE_TYPE (type), 0, 0); -} - -static void -output_compile_unit_die (arg) - void *arg; -{ - const char *main_input_filename = arg; - const char *language_string = lang_hooks.name; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit); - sibling_attribute (); - dienum_push (); - name_attribute (main_input_filename); - - { - char producer[250]; - - sprintf (producer, "%s %s", language_string, version_string); - producer_attribute (producer); - } - - if (strcmp (language_string, "GNU C++") == 0) - language_attribute (LANG_C_PLUS_PLUS); - else if (strcmp (language_string, "GNU Ada") == 0) - language_attribute (LANG_ADA83); - else if (strcmp (language_string, "GNU F77") == 0) - language_attribute (LANG_FORTRAN77); - else if (strcmp (language_string, "GNU Pascal") == 0) - language_attribute (LANG_PASCAL83); - else if (strcmp (language_string, "GNU Java") == 0) - language_attribute (LANG_JAVA); - else - language_attribute (LANG_C89); - low_pc_attribute (TEXT_BEGIN_LABEL); - high_pc_attribute (TEXT_END_LABEL); - if (debug_info_level >= DINFO_LEVEL_NORMAL) - stmt_list_attribute (LINE_BEGIN_LABEL); - - { - const char *wd = getpwd (); - if (wd) - comp_dir_attribute (wd); - } - - if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions) - { - sf_names_attribute (SFNAMES_BEGIN_LABEL); - src_info_attribute (SRCINFO_BEGIN_LABEL); - if (debug_info_level >= DINFO_LEVEL_VERBOSE) - mac_info_attribute (MACINFO_BEGIN_LABEL); - } -} - -static void -output_string_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - member_attribute (TYPE_CONTEXT (type)); - /* this is a fixed length string */ - byte_size_attribute (type); -} - -static void -output_inheritance_die (arg) - void *arg; -{ - tree binfo = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance); - sibling_attribute (); - type_attribute (BINFO_TYPE (binfo), 0, 0); - data_member_location_attribute (binfo); - if (TREE_VIA_VIRTUAL (binfo)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - } - if (TREE_VIA_PUBLIC (binfo)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - } - else if (TREE_VIA_PROTECTED (binfo)) - { - ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - } -} - -static void -output_structure_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - name_attribute (type_tag (type)); - member_attribute (TYPE_CONTEXT (type)); - - /* If this type has been completed, then give it a byte_size attribute - and prepare to give a list of members. Otherwise, don't do either of - these things. In the latter case, we will not be generating a list - of members (since we don't have any idea what they might be for an - incomplete type). */ - - if (COMPLETE_TYPE_P (type)) - { - dienum_push (); - byte_size_attribute (type); - } -} - -/* Output a DIE to represent a declared function (either file-scope - or block-local) which has "internal linkage" (according to ANSI-C). */ - -static void -output_local_subroutine_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine); - sibling_attribute (); - dienum_push (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - tree type = TREE_TYPE (decl); - - name_and_src_coords_attributes (decl); - inline_attribute (decl); - prototyped_attribute (type); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (TREE_TYPE (type), 0, 0); - pure_or_virtual_attribute (decl); - } - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); - else - { - /* Avoid getting screwed up in cases where a function was declared - static but where no definition was ever given for it. */ - - if (TREE_ASM_WRITTEN (decl)) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - low_pc_attribute (function_start_label (decl)); - sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no); - high_pc_attribute (label); - if (use_gnu_debug_info_extensions) - { - sprintf (label, BODY_BEGIN_LABEL_FMT, - current_function_funcdef_no); - body_begin_attribute (label); - sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no); - body_end_attribute (label); - } - } - } -} - -static void -output_subroutine_type_die (arg) - void *arg; -{ - tree type = arg; - tree return_type = TREE_TYPE (type); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type); - sibling_attribute (); - dienum_push (); - equate_type_number_to_die_number (type); - prototyped_attribute (type); - member_attribute (TYPE_CONTEXT (type)); - type_attribute (return_type, 0, 0); -} - -static void -output_typedef_die (arg) - void *arg; -{ - tree decl = arg; - tree origin = decl_ultimate_origin (decl); - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef); - sibling_attribute (); - if (origin != NULL) - abstract_origin_attribute (origin); - else - { - name_and_src_coords_attributes (decl); - member_attribute (DECL_CONTEXT (decl)); - type_attribute (TREE_TYPE (decl), - TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); - } - if (DECL_ABSTRACT (decl)) - equate_decl_number_to_die_number (decl); -} - -static void -output_union_type_die (arg) - void *arg; -{ - tree type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); - sibling_attribute (); - equate_type_number_to_die_number (type); - name_attribute (type_tag (type)); - member_attribute (TYPE_CONTEXT (type)); - - /* If this type has been completed, then give it a byte_size attribute - and prepare to give a list of members. Otherwise, don't do either of - these things. In the latter case, we will not be generating a list - of members (since we don't have any idea what they might be for an - incomplete type). */ - - if (COMPLETE_TYPE_P (type)) - { - dienum_push (); - byte_size_attribute (type); - } -} - -/* Generate a special type of DIE used as a stand-in for a trailing ellipsis - at the end of an (ANSI prototyped) formal parameters list. */ - -static void -output_unspecified_parameters_die (arg) - void *arg; -{ - tree decl_or_type = arg; - - ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters); - sibling_attribute (); - - /* This kludge is here only for the sake of being compatible with what - the USL CI5 C compiler does. The specification of Dwarf Version 1 - doesn't say that TAG_unspecified_parameters DIEs should contain any - attributes other than the AT_sibling attribute, but they are certainly - allowed to contain additional attributes, and the CI5 compiler - generates AT_name, AT_fund_type, and AT_location attributes within - TAG_unspecified_parameters DIEs which appear in the child lists for - DIEs representing function definitions, so we do likewise here. */ - - if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type)) - { - name_attribute ("..."); - fund_type_attribute (FT_pointer); - /* location_attribute (?); */ - } -} - -static void -output_padded_null_die (arg) - void *arg ATTRIBUTE_UNUSED; -{ - ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */ -} - -/*************************** end of DIEs *********************************/ - -/* Generate some type of DIE. This routine generates the generic outer - wrapper stuff which goes around all types of DIE's (regardless of their - TAGs. All forms of DIEs start with a DIE-specific label, followed by a - DIE-length word, followed by the guts of the DIE itself. After the guts - of the DIE, there must always be a terminator label for the DIE. */ - -static void -output_die (die_specific_output_function, param) - void (*die_specific_output_function) PARAMS ((void *)); - void *param; -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - current_dienum = NEXT_DIE_NUM; - NEXT_DIE_NUM = next_unused_dienum; - - sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); - sprintf (end_label, DIE_END_LABEL_FMT, current_dienum); - - /* Write a label which will act as the name for the start of this DIE. */ - - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - /* Write the DIE-length word. */ - - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); - - /* Fill in the guts of the DIE. */ - - next_unused_dienum++; - die_specific_output_function (param); - - /* Write a label which will act as the name for the end of this DIE. */ - - ASM_OUTPUT_LABEL (asm_out_file, end_label); -} - -static void -end_sibling_chain () -{ - char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - current_dienum = NEXT_DIE_NUM; - NEXT_DIE_NUM = next_unused_dienum; - - sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); - - /* Write a label which will act as the name for the start of this DIE. */ - - ASM_OUTPUT_LABEL (asm_out_file, begin_label); - - /* Write the DIE-length word. */ - - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); - - dienum_pop (); -} - -/* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a - TAG_unspecified_parameters DIE) to represent the types of the formal - parameters as specified in some function type specification (except - for those which appear as part of a function *definition*). - - Note that we must be careful here to output all of the parameter - DIEs *before* we output any DIEs needed to represent the types of - the formal parameters. This keeps svr4 SDB happy because it - (incorrectly) thinks that the first non-parameter DIE it sees ends - the formal parameter list. */ - -static void -output_formal_types (function_or_method_type) - tree function_or_method_type; -{ - tree link; - tree formal_type = NULL; - tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); - - /* Set TREE_ASM_WRITTEN while processing the parameters, lest we - get bogus recursion when outputting tagged types local to a - function declaration. */ - int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type); - TREE_ASM_WRITTEN (function_or_method_type) = 1; - - /* In the case where we are generating a formal types list for a C++ - non-static member function type, skip over the first thing on the - TYPE_ARG_TYPES list because it only represents the type of the - hidden `this pointer'. The debugger should be able to figure - out (without being explicitly told) that this non-static member - function type takes a `this pointer' and should be able to figure - what the type of that hidden parameter is from the AT_member - attribute of the parent TAG_subroutine_type DIE. */ - - if (TREE_CODE (function_or_method_type) == METHOD_TYPE) - first_parm_type = TREE_CHAIN (first_parm_type); - - /* Make our first pass over the list of formal parameter types and output - a TAG_formal_parameter DIE for each one. */ - - for (link = first_parm_type; link; link = TREE_CHAIN (link)) - { - formal_type = TREE_VALUE (link); - if (formal_type == void_type_node) - break; - - /* Output a (nameless) DIE to represent the formal parameter itself. */ - - output_die (output_formal_parameter_die, formal_type); - } - - /* If this function type has an ellipsis, add a TAG_unspecified_parameters - DIE to the end of the parameter list. */ - - if (formal_type != void_type_node) - output_die (output_unspecified_parameters_die, function_or_method_type); - - /* Make our second (and final) pass over the list of formal parameter types - and output DIEs to represent those types (as necessary). */ - - for (link = TYPE_ARG_TYPES (function_or_method_type); - link; - link = TREE_CHAIN (link)) - { - formal_type = TREE_VALUE (link); - if (formal_type == void_type_node) - break; - - output_type (formal_type, function_or_method_type); - } - - TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written; -} - -/* Remember a type in the pending_types_list. */ - -static void -pend_type (type) - tree type; -{ - if (pending_types == pending_types_allocated) - { - pending_types_allocated += PENDING_TYPES_INCREMENT; - pending_types_list - = (tree *) xrealloc (pending_types_list, - sizeof (tree) * pending_types_allocated); - } - pending_types_list[pending_types++] = type; - - /* Mark the pending type as having been output already (even though - it hasn't been). This prevents the type from being added to the - pending_types_list more than once. */ - - TREE_ASM_WRITTEN (type) = 1; -} - -/* Return nonzero if it is legitimate to output DIEs to represent a - given type while we are generating the list of child DIEs for some - DIE (e.g. a function or lexical block DIE) associated with a given scope. - - See the comments within the function for a description of when it is - considered legitimate to output DIEs for various kinds of types. - - Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope) - or it may point to a BLOCK node (for types local to a block), or to a - FUNCTION_DECL node (for types local to the heading of some function - definition), or to a FUNCTION_TYPE node (for types local to the - prototyped parameter list of a function type specification), or to a - RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node - (in the case of C++ nested types). - - The `scope' parameter should likewise be NULL or should point to a - BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE - node, a UNION_TYPE node, or a QUAL_UNION_TYPE node. - - This function is used only for deciding when to "pend" and when to - "un-pend" types to/from the pending_types_list. - - Note that we sometimes make use of this "type pending" feature in a - rather twisted way to temporarily delay the production of DIEs for the - types of formal parameters. (We do this just to make svr4 SDB happy.) - It order to delay the production of DIEs representing types of formal - parameters, callers of this function supply `fake_containing_scope' as - the `scope' parameter to this function. Given that fake_containing_scope - is a tagged type which is *not* the containing scope for *any* other type, - the desired effect is achieved, i.e. output of DIEs representing types - is temporarily suspended, and any type DIEs which would have otherwise - been output are instead placed onto the pending_types_list. Later on, - we force these (temporarily pended) types to be output simply by calling - `output_pending_types_for_scope' with an actual argument equal to the - true scope of the types we temporarily pended. */ - -static inline int -type_ok_for_scope (type, scope) - tree type; - tree scope; -{ - /* Tagged types (i.e. struct, union, and enum types) must always be - output only in the scopes where they actually belong (or else the - scoping of their own tag names and the scoping of their member - names will be incorrect). Non-tagged-types on the other hand can - generally be output anywhere, except that svr4 SDB really doesn't - want to see them nested within struct or union types, so here we - say it is always OK to immediately output any such a (non-tagged) - type, so long as we are not within such a context. Note that the - only kinds of non-tagged types which we will be dealing with here - (for C and C++ anyway) will be array types and function types. */ - - return is_tagged_type (type) - ? (TYPE_CONTEXT (type) == scope - /* Ignore namespaces for the moment. */ - || (scope == NULL_TREE - && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL) - || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type)) - && TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))) - : (scope == NULL_TREE || ! is_tagged_type (scope)); -} - -/* Output any pending types (from the pending_types list) which we can output - now (taking into account the scope that we are working on now). - - For each type output, remove the given type from the pending_types_list - *before* we try to output it. - - Note that we have to process the list in beginning-to-end order, - because the call made here to output_type may cause yet more types - to be added to the end of the list, and we may have to output some - of them too. */ - -static void -output_pending_types_for_scope (containing_scope) - tree containing_scope; -{ - unsigned i; - - for (i = 0; i < pending_types; ) - { - tree type = pending_types_list[i]; - - if (type_ok_for_scope (type, containing_scope)) - { - tree *mover; - tree *limit; - - pending_types--; - limit = &pending_types_list[pending_types]; - for (mover = &pending_types_list[i]; mover < limit; mover++) - *mover = *(mover+1); - - /* Un-mark the type as having been output already (because it - hasn't been, really). Then call output_type to generate a - Dwarf representation of it. */ - - TREE_ASM_WRITTEN (type) = 0; - output_type (type, containing_scope); - - /* Don't increment the loop counter in this case because we - have shifted all of the subsequent pending types down one - element in the pending_types_list array. */ - } - else - i++; - } -} - -/* Remember a type in the incomplete_types_list. */ - -static void -add_incomplete_type (type) - tree type; -{ - if (incomplete_types == incomplete_types_allocated) - { - incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; - incomplete_types_list - = (tree *) xrealloc (incomplete_types_list, - sizeof (tree) * incomplete_types_allocated); - } - - incomplete_types_list[incomplete_types++] = type; -} - -/* Walk through the list of incomplete types again, trying once more to - emit full debugging info for them. */ - -static void -retry_incomplete_types () -{ - tree type; - - finalizing = 1; - while (incomplete_types) - { - --incomplete_types; - type = incomplete_types_list[incomplete_types]; - output_type (type, NULL_TREE); - } -} - -static void -output_type (type, containing_scope) - tree type; - tree containing_scope; -{ - if (type == 0 || type == error_mark_node) - return; - - /* We are going to output a DIE to represent the unqualified version of - this type (i.e. without any const or volatile qualifiers) so get - the main variant (i.e. the unqualified version) of this type now. */ - - type = type_main_variant (type); - - if (TREE_ASM_WRITTEN (type)) - { - if (finalizing && AGGREGATE_TYPE_P (type)) - { - tree member; - - /* Some of our nested types might not have been defined when we - were written out before; force them out now. */ - - for (member = TYPE_FIELDS (type); member; - member = TREE_CHAIN (member)) - if (TREE_CODE (member) == TYPE_DECL - && ! TREE_ASM_WRITTEN (TREE_TYPE (member))) - output_type (TREE_TYPE (member), containing_scope); - } - return; - } - - /* If this is a nested type whose containing class hasn't been - written out yet, writing it out will cover this one, too. */ - - if (TYPE_CONTEXT (type) - && TYPE_P (TYPE_CONTEXT (type)) - && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) - { - output_type (TYPE_CONTEXT (type), containing_scope); - return; - } - - /* Don't generate any DIEs for this type now unless it is OK to do so - (based upon what `type_ok_for_scope' tells us). */ - - if (! type_ok_for_scope (type, containing_scope)) - { - pend_type (type); - return; - } - - switch (TREE_CODE (type)) - { - case ERROR_MARK: - break; - - case VECTOR_TYPE: - output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope); - break; - - case POINTER_TYPE: - case REFERENCE_TYPE: - /* Prevent infinite recursion in cases where this is a recursive - type. Recursive types are possible in Ada. */ - TREE_ASM_WRITTEN (type) = 1; - /* For these types, all that is required is that we output a DIE - (or a set of DIEs) to represent the "basis" type. */ - output_type (TREE_TYPE (type), containing_scope); - break; - - case OFFSET_TYPE: - /* This code is used for C++ pointer-to-data-member types. */ - /* Output a description of the relevant class type. */ - output_type (TYPE_OFFSET_BASETYPE (type), containing_scope); - /* Output a description of the type of the object pointed to. */ - output_type (TREE_TYPE (type), containing_scope); - /* Now output a DIE to represent this pointer-to-data-member type - itself. */ - output_die (output_ptr_to_mbr_type_die, type); - break; - - case SET_TYPE: - output_type (TYPE_DOMAIN (type), containing_scope); - output_die (output_set_type_die, type); - break; - - case FILE_TYPE: - output_type (TREE_TYPE (type), containing_scope); - abort (); /* No way to represent these in Dwarf yet! */ - break; - - case FUNCTION_TYPE: - /* Force out return type (in case it wasn't forced out already). */ - output_type (TREE_TYPE (type), containing_scope); - output_die (output_subroutine_type_die, type); - output_formal_types (type); - end_sibling_chain (); - break; - - case METHOD_TYPE: - /* Force out return type (in case it wasn't forced out already). */ - output_type (TREE_TYPE (type), containing_scope); - output_die (output_subroutine_type_die, type); - output_formal_types (type); - end_sibling_chain (); - break; - - case ARRAY_TYPE: - if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE) - { - output_type (TREE_TYPE (type), containing_scope); - output_die (output_string_type_die, type); - } - else - { - tree element_type; - - element_type = TREE_TYPE (type); - while (TREE_CODE (element_type) == ARRAY_TYPE) - element_type = TREE_TYPE (element_type); - - output_type (element_type, containing_scope); - output_die (output_array_type_die, type); - } - break; - - case ENUMERAL_TYPE: - case RECORD_TYPE: - case UNION_TYPE: - case QUAL_UNION_TYPE: - - /* For a non-file-scope tagged type, we can always go ahead and - output a Dwarf description of this type right now, even if - the type in question is still incomplete, because if this - local type *was* ever completed anywhere within its scope, - that complete definition would already have been attached to - this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE - node by the time we reach this point. That's true because of the - way the front-end does its processing of file-scope declarations (of - functions and class types) within which other types might be - nested. The C and C++ front-ends always gobble up such "local - scope" things en-mass before they try to output *any* debugging - information for any of the stuff contained inside them and thus, - we get the benefit here of what is (in effect) a pre-resolution - of forward references to tagged types in local scopes. - - Note however that for file-scope tagged types we cannot assume - that such pre-resolution of forward references has taken place. - A given file-scope tagged type may appear to be incomplete when - we reach this point, but it may yet be given a full definition - (at file-scope) later on during compilation. In order to avoid - generating a premature (and possibly incorrect) set of Dwarf - DIEs for such (as yet incomplete) file-scope tagged types, we - generate nothing at all for as-yet incomplete file-scope tagged - types here unless we are making our special "finalization" pass - for file-scope things at the very end of compilation. At that - time, we will certainly know as much about each file-scope tagged - type as we are ever going to know, so at that point in time, we - can safely generate correct Dwarf descriptions for these file- - scope tagged types. */ - - if (!COMPLETE_TYPE_P (type) - && (TYPE_CONTEXT (type) == NULL - || AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) - || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL) - && !finalizing) - { - /* We don't need to do this for function-local types. */ - if (! decl_function_context (TYPE_STUB_DECL (type))) - add_incomplete_type (type); - return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */ - } - - /* Prevent infinite recursion in cases where the type of some - member of this type is expressed in terms of this type itself. */ - - TREE_ASM_WRITTEN (type) = 1; - - /* Output a DIE to represent the tagged type itself. */ - - switch (TREE_CODE (type)) - { - case ENUMERAL_TYPE: - output_die (output_enumeration_type_die, type); - return; /* a special case -- nothing left to do so just return */ - - case RECORD_TYPE: - output_die (output_structure_type_die, type); - break; - - case UNION_TYPE: - case QUAL_UNION_TYPE: - output_die (output_union_type_die, type); - break; - - default: - abort (); /* Should never happen. */ - } - - /* If this is not an incomplete type, output descriptions of - each of its members. - - Note that as we output the DIEs necessary to represent the - members of this record or union type, we will also be trying - to output DIEs to represent the *types* of those members. - However the `output_type' function (above) will specifically - avoid generating type DIEs for member types *within* the list - of member DIEs for this (containing) type except for those - types (of members) which are explicitly marked as also being - members of this (containing) type themselves. The g++ front- - end can force any given type to be treated as a member of some - other (containing) type by setting the TYPE_CONTEXT of the - given (member) type to point to the TREE node representing the - appropriate (containing) type. - */ - - if (COMPLETE_TYPE_P (type)) - { - /* First output info about the base classes. */ - if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) - { - register tree bases = TYPE_BINFO_BASETYPES (type); - register int n_bases = TREE_VEC_LENGTH (bases); - register int i; - - for (i = 0; i < n_bases; i++) - { - tree binfo = TREE_VEC_ELT (bases, i); - output_type (BINFO_TYPE (binfo), containing_scope); - output_die (output_inheritance_die, binfo); - } - } - - ++in_class; - - { - tree normal_member; - - /* Now output info about the data members and type members. */ - - for (normal_member = TYPE_FIELDS (type); - normal_member; - normal_member = TREE_CHAIN (normal_member)) - output_decl (normal_member, type); - } - - { - tree func_member; - - /* Now output info about the function members (if any). */ - - for (func_member = TYPE_METHODS (type); - func_member; - func_member = TREE_CHAIN (func_member)) - { - /* Don't include clones in the member list. */ - if (DECL_ABSTRACT_ORIGIN (func_member)) - continue; - - output_decl (func_member, type); - } - } - - --in_class; - - /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves - scopes (at least in C++) so we must now output any nested - pending types which are local just to this type. */ - - output_pending_types_for_scope (type); - - end_sibling_chain (); /* Terminate member chain. */ - } - - break; - - case VOID_TYPE: - case INTEGER_TYPE: - case REAL_TYPE: - case COMPLEX_TYPE: - case BOOLEAN_TYPE: - case CHAR_TYPE: - break; /* No DIEs needed for fundamental types. */ - - case LANG_TYPE: /* No Dwarf representation currently defined. */ - break; - - default: - abort (); - } - - TREE_ASM_WRITTEN (type) = 1; -} - -static void -output_tagged_type_instantiation (type) - tree type; -{ - if (type == 0 || type == error_mark_node) - return; - - /* We are going to output a DIE to represent the unqualified version of - this type (i.e. without any const or volatile qualifiers) so make - sure that we have the main variant (i.e. the unqualified version) of - this type now. */ - - if (type != type_main_variant (type)) - abort (); - - if (!TREE_ASM_WRITTEN (type)) - abort (); - - switch (TREE_CODE (type)) - { - case ERROR_MARK: - break; - - case ENUMERAL_TYPE: - output_die (output_inlined_enumeration_type_die, type); - break; - - case RECORD_TYPE: - output_die (output_inlined_structure_type_die, type); - break; - - case UNION_TYPE: - case QUAL_UNION_TYPE: - output_die (output_inlined_union_type_die, type); - break; - - default: - abort (); /* Should never happen. */ - } -} - -/* Output a TAG_lexical_block DIE followed by DIEs to represent all of - the things which are local to the given block. */ - -static void -output_block (stmt, depth) - tree stmt; - int depth; -{ - int must_output_die = 0; - tree origin; - enum tree_code origin_code; - - /* Ignore blocks never really used to make RTL. */ - - if (! stmt || ! TREE_USED (stmt) - || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) - return; - - /* Determine the "ultimate origin" of this block. This block may be an - inlined instance of an inlined instance of inline function, so we - have to trace all of the way back through the origin chain to find - out what sort of node actually served as the original seed for the - creation of the current block. */ - - origin = block_ultimate_origin (stmt); - origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; - - /* Determine if we need to output any Dwarf DIEs at all to represent this - block. */ - - if (origin_code == FUNCTION_DECL) - /* The outer scopes for inlinings *must* always be represented. We - generate TAG_inlined_subroutine DIEs for them. (See below.) */ - must_output_die = 1; - else - { - /* In the case where the current block represents an inlining of the - "body block" of an inline function, we must *NOT* output any DIE - for this block because we have already output a DIE to represent - the whole inlined function scope and the "body block" of any - function doesn't really represent a different scope according to - ANSI C rules. So we check here to make sure that this block does - not represent a "body block inlining" before trying to set the - `must_output_die' flag. */ - - if (! is_body_block (origin ? origin : stmt)) - { - /* Determine if this block directly contains any "significant" - local declarations which we will need to output DIEs for. */ - - if (debug_info_level > DINFO_LEVEL_TERSE) - /* We are not in terse mode so *any* local declaration counts - as being a "significant" one. */ - must_output_die = (BLOCK_VARS (stmt) != NULL); - else - { - tree decl; - - /* We are in terse mode, so only local (nested) function - definitions count as "significant" local declarations. */ - - for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) - if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) - { - must_output_die = 1; - break; - } - } - } - } - - /* It would be a waste of space to generate a Dwarf TAG_lexical_block - DIE for any block which contains no significant local declarations - at all. Rather, in such cases we just call `output_decls_for_scope' - so that any needed Dwarf info for any sub-blocks will get properly - generated. Note that in terse mode, our definition of what constitutes - a "significant" local declaration gets restricted to include only - inlined function instances and local (nested) function definitions. */ - - if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt)) - /* We don't care about an abstract inlined subroutine. */; - else if (must_output_die) - { - output_die ((origin_code == FUNCTION_DECL) - ? output_inlined_subroutine_die - : output_lexical_block_die, - stmt); - output_decls_for_scope (stmt, depth); - end_sibling_chain (); - } - else - output_decls_for_scope (stmt, depth); -} - -/* Output all of the decls declared within a given scope (also called - a `binding contour') and (recursively) all of it's sub-blocks. */ - -static void -output_decls_for_scope (stmt, depth) - tree stmt; - int depth; -{ - /* Ignore blocks never really used to make RTL. */ - - if (! stmt || ! TREE_USED (stmt)) - return; - - /* Output the DIEs to represent all of the data objects, functions, - typedefs, and tagged types declared directly within this block - but not within any nested sub-blocks. */ - - { - tree decl; - - for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) - output_decl (decl, stmt); - } - - output_pending_types_for_scope (stmt); - - /* Output the DIEs to represent all sub-blocks (and the items declared - therein) of this block. */ - - { - tree subblocks; - - for (subblocks = BLOCK_SUBBLOCKS (stmt); - subblocks; - subblocks = BLOCK_CHAIN (subblocks)) - output_block (subblocks, depth + 1); - } -} - -/* Is this a typedef we can avoid emitting? */ - -static inline int -is_redundant_typedef (decl) - tree decl; -{ - if (TYPE_DECL_IS_STUB (decl)) - return 1; - if (DECL_ARTIFICIAL (decl) - && DECL_CONTEXT (decl) - && is_tagged_type (DECL_CONTEXT (decl)) - && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL - && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) - /* Also ignore the artificial member typedef for the class name. */ - return 1; - return 0; -} - -/* Output Dwarf .debug information for a decl described by DECL. */ - -static void -output_decl (decl, containing_scope) - tree decl; - tree containing_scope; -{ - /* Make a note of the decl node we are going to be working on. We may - need to give the user the source coordinates of where it appeared in - case we notice (later on) that something about it looks screwy. */ - - dwarf_last_decl = decl; - - if (TREE_CODE (decl) == ERROR_MARK) - return; - - /* If a structure is declared within an initialization, e.g. as the - operand of a sizeof, then it will not have a name. We don't want - to output a DIE for it, as the tree nodes are in the temporary obstack */ - - if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) - && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0) - || (TYPE_FIELDS (TREE_TYPE (decl)) - && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK)))) - return; - - /* If this ..._DECL node is marked to be ignored, then ignore it. */ - - if (DECL_IGNORED_P (decl)) - return; - - switch (TREE_CODE (decl)) - { - case CONST_DECL: - /* The individual enumerators of an enum type get output when we - output the Dwarf representation of the relevant enum type itself. */ - break; - - case FUNCTION_DECL: - /* If we are in terse mode, don't output any DIEs to represent - mere function declarations. Also, if we are conforming - to the DWARF version 1 specification, don't output DIEs for - mere function declarations. */ - - if (DECL_INITIAL (decl) == NULL_TREE) -#if (DWARF_VERSION > 1) - if (debug_info_level <= DINFO_LEVEL_TERSE) -#endif - break; - - /* Before we describe the FUNCTION_DECL itself, make sure that we - have described its return type. */ - - output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope); - - { - /* And its containing type. */ - register tree origin = decl_class_context (decl); - if (origin) - output_type (origin, containing_scope); - } - - /* If we're emitting an out-of-line copy of an inline function, - set up to refer to the abstract instance emitted from - dwarfout_deferred_inline_function. */ - if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) - && ! (containing_scope && TYPE_P (containing_scope))) - set_decl_origin_self (decl); - - /* If the following DIE will represent a function definition for a - function with "extern" linkage, output a special "pubnames" DIE - label just ahead of the actual DIE. A reference to this label - was already generated in the .debug_pubnames section sub-entry - for this function definition. */ - - if (TREE_PUBLIC (decl)) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); - ASM_OUTPUT_LABEL (asm_out_file, label); - } - - /* Now output a DIE to represent the function itself. */ - - output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl) - ? output_global_subroutine_die - : output_local_subroutine_die, - decl); - - /* Now output descriptions of the arguments for this function. - This gets (unnecessarily?) complex because of the fact that - the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate - cases where there was a trailing `...' at the end of the formal - parameter list. In order to find out if there was a trailing - ellipsis or not, we must instead look at the type associated - with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE. - If the chain of type nodes hanging off of this FUNCTION_TYPE node - ends with a void_type_node then there should *not* be an ellipsis - at the end. */ - - /* In the case where we are describing a mere function declaration, all - we need to do here (and all we *can* do here) is to describe - the *types* of its formal parameters. */ - - if (decl != current_function_decl || in_class) - output_formal_types (TREE_TYPE (decl)); - else - { - /* Generate DIEs to represent all known formal parameters */ - - tree arg_decls = DECL_ARGUMENTS (decl); - tree parm; - - /* WARNING! Kludge zone ahead! Here we have a special - hack for svr4 SDB compatibility. Instead of passing the - current FUNCTION_DECL node as the second parameter (i.e. - the `containing_scope' parameter) to `output_decl' (as - we ought to) we instead pass a pointer to our own private - fake_containing_scope node. That node is a RECORD_TYPE - node which NO OTHER TYPE may ever actually be a member of. - - This pointer will ultimately get passed into `output_type' - as its `containing_scope' parameter. `Output_type' will - then perform its part in the hack... i.e. it will pend - the type of the formal parameter onto the pending_types - list. Later on, when we are done generating the whole - sequence of formal parameter DIEs for this function - definition, we will un-pend all previously pended types - of formal parameters for this function definition. - - This whole kludge prevents any type DIEs from being - mixed in with the formal parameter DIEs. That's good - because svr4 SDB believes that the list of formal - parameter DIEs for a function ends wherever the first - non-formal-parameter DIE appears. Thus, we have to - keep the formal parameter DIEs segregated. They must - all appear (consecutively) at the start of the list of - children for the DIE representing the function definition. - Then (and only then) may we output any additional DIEs - needed to represent the types of these formal parameters. - */ - - /* - When generating DIEs, generate the unspecified_parameters - DIE instead if we come across the arg "__builtin_va_alist" - */ - - for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) - if (TREE_CODE (parm) == PARM_DECL) - { - if (DECL_NAME(parm) && - !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)), - "__builtin_va_alist") ) - output_die (output_unspecified_parameters_die, decl); - else - output_decl (parm, fake_containing_scope); - } - - /* - Now that we have finished generating all of the DIEs to - represent the formal parameters themselves, force out - any DIEs needed to represent their types. We do this - simply by un-pending all previously pended types which - can legitimately go into the chain of children DIEs for - the current FUNCTION_DECL. - */ - - output_pending_types_for_scope (decl); - - /* - Decide whether we need an unspecified_parameters DIE at the end. - There are 2 more cases to do this for: - 1) the ansi ... declaration - this is detectable when the end - of the arg list is not a void_type_node - 2) an unprototyped function declaration (not a definition). This - just means that we have no info about the parameters at all. - */ - - { - tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); - - if (fn_arg_types) - { - /* this is the prototyped case, check for ... */ - if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) - output_die (output_unspecified_parameters_die, decl); - } - else - { - /* this is unprototyped, check for undefined (just declaration) */ - if (!DECL_INITIAL (decl)) - output_die (output_unspecified_parameters_die, decl); - } - } - - /* Output Dwarf info for all of the stuff within the body of the - function (if it has one - it may be just a declaration). */ - - { - tree outer_scope = DECL_INITIAL (decl); - - if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK) - { - /* Note that here, `outer_scope' is a pointer to the outermost - BLOCK node created to represent a function. - This outermost BLOCK actually represents the outermost - binding contour for the function, i.e. the contour in which - the function's formal parameters and labels get declared. - - Curiously, it appears that the front end doesn't actually - put the PARM_DECL nodes for the current function onto the - BLOCK_VARS list for this outer scope. (They are strung - off of the DECL_ARGUMENTS list for the function instead.) - The BLOCK_VARS list for the `outer_scope' does provide us - with a list of the LABEL_DECL nodes for the function however, - and we output DWARF info for those here. - - Just within the `outer_scope' there will be a BLOCK node - representing the function's outermost pair of curly braces, - and any blocks used for the base and member initializers of - a C++ constructor function. */ - - output_decls_for_scope (outer_scope, 0); - - /* Finally, force out any pending types which are local to the - outermost block of this function definition. These will - all have a TYPE_CONTEXT which points to the FUNCTION_DECL - node itself. */ - - output_pending_types_for_scope (decl); - } - } - } - - /* Generate a terminator for the list of stuff `owned' by this - function. */ - - end_sibling_chain (); - - break; - - case TYPE_DECL: - /* If we are in terse mode, don't generate any DIEs to represent - any actual typedefs. Note that even when we are in terse mode, - we must still output DIEs to represent those tagged types which - are used (directly or indirectly) in the specification of either - a return type or a formal parameter type of some function. */ - - if (debug_info_level <= DINFO_LEVEL_TERSE) - if (! TYPE_DECL_IS_STUB (decl) - || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class)) - return; - - /* In the special case of a TYPE_DECL node representing - the declaration of some type tag, if the given TYPE_DECL is - marked as having been instantiated from some other (original) - TYPE_DECL node (e.g. one which was generated within the original - definition of an inline function) we have to generate a special - (abbreviated) TAG_structure_type, TAG_union_type, or - TAG_enumeration-type DIE here. */ - - if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl)) - { - output_tagged_type_instantiation (TREE_TYPE (decl)); - return; - } - - output_type (TREE_TYPE (decl), containing_scope); - - if (! is_redundant_typedef (decl)) - /* Output a DIE to represent the typedef itself. */ - output_die (output_typedef_die, decl); - break; - - case LABEL_DECL: - if (debug_info_level >= DINFO_LEVEL_NORMAL) - output_die (output_label_die, decl); - break; - - case VAR_DECL: - /* If we are conforming to the DWARF version 1 specification, don't - generated any DIEs to represent mere external object declarations. */ - -#if (DWARF_VERSION <= 1) - if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl)) - break; -#endif - - /* If we are in terse mode, don't generate any DIEs to represent - any variable declarations or definitions. */ - - if (debug_info_level <= DINFO_LEVEL_TERSE) - break; - - /* Output any DIEs that are needed to specify the type of this data - object. */ - - output_type (TREE_TYPE (decl), containing_scope); - - { - /* And its containing type. */ - register tree origin = decl_class_context (decl); - if (origin) - output_type (origin, containing_scope); - } - - /* If the following DIE will represent a data object definition for a - data object with "extern" linkage, output a special "pubnames" DIE - label just ahead of the actual DIE. A reference to this label - was already generated in the .debug_pubnames section sub-entry - for this data object definition. */ - - if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl)) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); - ASM_OUTPUT_LABEL (asm_out_file, label); - } - - /* Now output the DIE to represent the data object itself. This gets - complicated because of the possibility that the VAR_DECL really - represents an inlined instance of a formal parameter for an inline - function. */ - - { - void (*func) PARAMS ((void *)); - register tree origin = decl_ultimate_origin (decl); - - if (origin != NULL && TREE_CODE (origin) == PARM_DECL) - func = output_formal_parameter_die; - else - { - if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) - func = output_global_variable_die; - else - func = output_local_variable_die; - } - output_die (func, decl); - } - break; - - case FIELD_DECL: - /* Ignore the nameless fields that are used to skip bits. */ - if (DECL_NAME (decl) != 0) - { - output_type (member_declared_type (decl), containing_scope); - output_die (output_member_die, decl); - } - break; - - case PARM_DECL: - /* Force out the type of this formal, if it was not forced out yet. - Note that here we can run afoul of a bug in "classic" svr4 SDB. - It should be able to grok the presence of type DIEs within a list - of TAG_formal_parameter DIEs, but it doesn't. */ - - output_type (TREE_TYPE (decl), containing_scope); - output_die (output_formal_parameter_die, decl); - break; - - case NAMESPACE_DECL: - /* Ignore for now. */ - break; - - default: - abort (); - } -} - -/* Output debug information for a function. */ -static void -dwarfout_function_decl (decl) - tree decl; -{ - dwarfout_file_scope_decl (decl, 0); -} - -/* Debug information for a global DECL. Called from toplev.c after - compilation proper has finished. */ -static void -dwarfout_global_decl (decl) - tree decl; -{ - /* Output DWARF information for file-scope tentative data object - declarations, file-scope (extern) function declarations (which - had no corresponding body) and file-scope tagged type - declarations and definitions which have not yet been forced out. */ - - if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) - dwarfout_file_scope_decl (decl, 1); -} - -/* DECL is an inline function, whose body is present, but which is not - being output at this point. (We're putting that off until we need - to do it.) */ -static void -dwarfout_deferred_inline_function (decl) - tree decl; -{ - /* Generate the DWARF info for the "abstract" instance of a function - which we may later generate inlined and/or out-of-line instances - of. */ - if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl)) - && ! DECL_ABSTRACT_ORIGIN (decl)) - { - /* The front-end may not have set CURRENT_FUNCTION_DECL, but the - DWARF code expects it to be set in this case. Intuitively, - DECL is the function we just finished defining, so setting - CURRENT_FUNCTION_DECL is sensible. */ - tree saved_cfd = current_function_decl; - int was_abstract = DECL_ABSTRACT (decl); - current_function_decl = decl; - - /* Let the DWARF code do its work. */ - set_decl_abstract_flags (decl, 1); - dwarfout_file_scope_decl (decl, 0); - if (! was_abstract) - set_decl_abstract_flags (decl, 0); - - /* Reset CURRENT_FUNCTION_DECL. */ - current_function_decl = saved_cfd; - } -} - -static void -dwarfout_file_scope_decl (decl, set_finalizing) - tree decl; - int set_finalizing; -{ - if (TREE_CODE (decl) == ERROR_MARK) - return; - - /* If this ..._DECL node is marked to be ignored, then ignore it. */ - - if (DECL_IGNORED_P (decl)) - return; - - switch (TREE_CODE (decl)) - { - case FUNCTION_DECL: - - /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of - a builtin function. Explicit programmer-supplied declarations of - these same functions should NOT be ignored however. */ - - if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) - return; - - /* What we would really like to do here is to filter out all mere - file-scope declarations of file-scope functions which are never - referenced later within this translation unit (and keep all of - ones that *are* referenced later on) but we aren't clairvoyant, - so we have no idea which functions will be referenced in the - future (i.e. later on within the current translation unit). - So here we just ignore all file-scope function declarations - which are not also definitions. If and when the debugger needs - to know something about these functions, it will have to hunt - around and find the DWARF information associated with the - *definition* of the function. - - Note that we can't just check `DECL_EXTERNAL' to find out which - FUNCTION_DECL nodes represent definitions and which ones represent - mere declarations. We have to check `DECL_INITIAL' instead. That's - because the C front-end supports some weird semantics for "extern - inline" function definitions. These can get inlined within the - current translation unit (an thus, we need to generate DWARF info - for their abstract instances so that the DWARF info for the - concrete inlined instances can have something to refer to) but - the compiler never generates any out-of-lines instances of such - things (despite the fact that they *are* definitions). The - important point is that the C front-end marks these "extern inline" - functions as DECL_EXTERNAL, but we need to generate DWARF for them - anyway. - - Note that the C++ front-end also plays some similar games for inline - function definitions appearing within include files which also - contain `#pragma interface' pragmas. */ - - if (DECL_INITIAL (decl) == NULL_TREE) - return; - - if (TREE_PUBLIC (decl) - && ! DECL_EXTERNAL (decl) - && ! DECL_ABSTRACT (decl)) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - /* Output a .debug_pubnames entry for a public function - defined in this compilation unit. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); - sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, - IDENTIFIER_POINTER (DECL_NAME (decl))); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - break; - - case VAR_DECL: - - /* Ignore this VAR_DECL if it refers to a file-scope extern data - object declaration and if the declaration was never even - referenced from within this entire compilation unit. We - suppress these DIEs in order to save space in the .debug section - (by eliminating entries which are probably useless). Note that - we must not suppress block-local extern declarations (whether - used or not) because that would screw-up the debugger's name - lookup mechanism and cause it to miss things which really ought - to be in scope at a given point. */ - - if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) - return; - - if (TREE_PUBLIC (decl) - && ! DECL_EXTERNAL (decl) - && GET_CODE (DECL_RTL (decl)) == MEM - && ! DECL_ABSTRACT (decl)) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - if (debug_info_level >= DINFO_LEVEL_NORMAL) - { - /* Output a .debug_pubnames entry for a public variable - defined in this compilation unit. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); - sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, - IDENTIFIER_POINTER (DECL_NAME (decl))); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - if (DECL_INITIAL (decl) == NULL) - { - /* Output a .debug_aranges entry for a public variable - which is tentatively defined in this compilation unit. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, - (unsigned) int_size_in_bytes (TREE_TYPE (decl))); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - } - - /* If we are in terse mode, don't generate any DIEs to represent - any variable declarations or definitions. */ - - if (debug_info_level <= DINFO_LEVEL_TERSE) - return; - - break; - - case TYPE_DECL: - /* Don't bother trying to generate any DIEs to represent any of the - normal built-in types for the language we are compiling, except - in cases where the types in question are *not* DWARF fundamental - types. We make an exception in the case of non-fundamental types - for the sake of objective C (and perhaps C++) because the GNU - front-ends for these languages may in fact create certain "built-in" - types which are (for example) RECORD_TYPEs. In such cases, we - really need to output these (non-fundamental) types because other - DIEs may contain references to them. */ - - /* Also ignore language dependent types here, because they are probably - also built-in types. If we didn't ignore them, then we would get - references to undefined labels because output_type doesn't support - them. So, for now, we need to ignore them to avoid assembler - errors. */ - - /* ??? This code is different than the equivalent code in dwarf2out.c. - The dwarf2out.c code is probably more correct. */ - - if (DECL_SOURCE_LINE (decl) == 0 - && (type_is_fundamental (TREE_TYPE (decl)) - || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE)) - return; - - /* If we are in terse mode, don't generate any DIEs to represent - any actual typedefs. Note that even when we are in terse mode, - we must still output DIEs to represent those tagged types which - are used (directly or indirectly) in the specification of either - a return type or a formal parameter type of some function. */ - - if (debug_info_level <= DINFO_LEVEL_TERSE) - if (! TYPE_DECL_IS_STUB (decl) - || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) - return; - - break; - - default: - return; - } - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); - finalizing = set_finalizing; - output_decl (decl, NULL_TREE); - - /* NOTE: The call above to `output_decl' may have caused one or more - file-scope named types (i.e. tagged types) to be placed onto the - pending_types_list. We have to get those types off of that list - at some point, and this is the perfect time to do it. If we didn't - take them off now, they might still be on the list when cc1 finally - exits. That might be OK if it weren't for the fact that when we put - types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag - for these types, and that causes them never to be output unless - `output_pending_types_for_scope' takes them off of the list and un-sets - their TREE_ASM_WRITTEN flags. */ - - output_pending_types_for_scope (NULL_TREE); - - /* The above call should have totally emptied the pending_types_list - if this is not a nested function or class. If this is a nested type, - then the remaining pending_types will be emitted when the containing type - is handled. */ - - if (! DECL_CONTEXT (decl)) - { - if (pending_types != 0) - abort (); - } - - ASM_OUTPUT_POP_SECTION (asm_out_file); -} - -/* Output a marker (i.e. a label) for the beginning of the generated code - for a lexical block. */ - -static void -dwarfout_begin_block (line, blocknum) - unsigned int line ATTRIBUTE_UNUSED; - unsigned int blocknum; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - function_section (current_function_decl); - sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum); - ASM_OUTPUT_LABEL (asm_out_file, label); -} - -/* Output a marker (i.e. a label) for the end of the generated code - for a lexical block. */ - -static void -dwarfout_end_block (line, blocknum) - unsigned int line ATTRIBUTE_UNUSED; - unsigned int blocknum; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - function_section (current_function_decl); - sprintf (label, BLOCK_END_LABEL_FMT, blocknum); - ASM_OUTPUT_LABEL (asm_out_file, label); -} - -/* Output a marker (i.e. a label) for the point in the generated code where - the real body of the function begins (after parameters have been moved - to their home locations). */ - -static void -dwarfout_end_prologue (line, file) - unsigned int line ATTRIBUTE_UNUSED; - const char *file ATTRIBUTE_UNUSED; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - if (! use_gnu_debug_info_extensions) - return; - - function_section (current_function_decl); - sprintf (label, BODY_BEGIN_LABEL_FMT, current_function_funcdef_no); - ASM_OUTPUT_LABEL (asm_out_file, label); -} - -/* Output a marker (i.e. a label) for the point in the generated code where - the real body of the function ends (just before the epilogue code). */ - -static void -dwarfout_end_function (line) - unsigned int line ATTRIBUTE_UNUSED; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - if (! use_gnu_debug_info_extensions) - return; - function_section (current_function_decl); - sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no); - ASM_OUTPUT_LABEL (asm_out_file, label); -} - -/* Output a marker (i.e. a label) for the absolute end of the generated code - for a function definition. This gets called *after* the epilogue code - has been generated. */ - -static void -dwarfout_end_epilogue (line, file) - unsigned int line ATTRIBUTE_UNUSED; - const char *file ATTRIBUTE_UNUSED; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - /* Output a label to mark the endpoint of the code generated for this - function. */ - - sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no); - ASM_OUTPUT_LABEL (asm_out_file, label); -} - -static void -shuffle_filename_entry (new_zeroth) - filename_entry *new_zeroth; -{ - filename_entry temp_entry; - filename_entry *limit_p; - filename_entry *move_p; - - if (new_zeroth == &filename_table[0]) - return; - - temp_entry = *new_zeroth; - - /* Shift entries up in the table to make room at [0]. */ - - limit_p = &filename_table[0]; - for (move_p = new_zeroth; move_p > limit_p; move_p--) - *move_p = *(move_p-1); - - /* Install the found entry at [0]. */ - - filename_table[0] = temp_entry; -} - -/* Create a new (string) entry for the .debug_sfnames section. */ - -static void -generate_new_sfname_entry () -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION); - sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number); - ASM_OUTPUT_LABEL (asm_out_file, label); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, - filename_table[0].name - ? filename_table[0].name - : ""); - ASM_OUTPUT_POP_SECTION (asm_out_file); -} - -/* Lookup a filename (in the list of filenames that we know about here in - dwarfout.c) and return its "index". The index of each (known) filename - is just a unique number which is associated with only that one filename. - We need such numbers for the sake of generating labels (in the - .debug_sfnames section) and references to those unique labels (in the - .debug_srcinfo and .debug_macinfo sections). - - If the filename given as an argument is not found in our current list, - add it to the list and assign it the next available unique index number. - - Whatever we do (i.e. whether we find a pre-existing filename or add a new - one), we shuffle the filename found (or added) up to the zeroth entry of - our list of filenames (which is always searched linearly). We do this so - as to optimize the most common case for these filename lookups within - dwarfout.c. The most common case by far is the case where we call - lookup_filename to lookup the very same filename that we did a lookup - on the last time we called lookup_filename. We make sure that this - common case is fast because such cases will constitute 99.9% of the - lookups we ever do (in practice). - - If we add a new filename entry to our table, we go ahead and generate - the corresponding entry in the .debug_sfnames section right away. - Doing so allows us to avoid tickling an assembler bug (present in some - m68k assemblers) which yields assembly-time errors in cases where the - difference of two label addresses is taken and where the two labels - are in a section *other* than the one where the difference is being - calculated, and where at least one of the two symbol references is a - forward reference. (This bug could be tickled by our .debug_srcinfo - entries if we don't output their corresponding .debug_sfnames entries - before them.) */ - -static unsigned -lookup_filename (file_name) - const char *file_name; -{ - filename_entry *search_p; - filename_entry *limit_p = &filename_table[ft_entries]; - - for (search_p = filename_table; search_p < limit_p; search_p++) - if (!strcmp (file_name, search_p->name)) - { - /* When we get here, we have found the filename that we were - looking for in the filename_table. Now we want to make sure - that it gets moved to the zero'th entry in the table (if it - is not already there) so that subsequent attempts to find the - same filename will find it as quickly as possible. */ - - shuffle_filename_entry (search_p); - return filename_table[0].number; - } - - /* We come here whenever we have a new filename which is not registered - in the current table. Here we add it to the table. */ - - /* Prepare to add a new table entry by making sure there is enough space - in the table to do so. If not, expand the current table. */ - - if (ft_entries == ft_entries_allocated) - { - ft_entries_allocated += FT_ENTRIES_INCREMENT; - filename_table - = (filename_entry *) - xrealloc (filename_table, - ft_entries_allocated * sizeof (filename_entry)); - } - - /* Initially, add the new entry at the end of the filename table. */ - - filename_table[ft_entries].number = ft_entries; - filename_table[ft_entries].name = xstrdup (file_name); - - /* Shuffle the new entry into filename_table[0]. */ - - shuffle_filename_entry (&filename_table[ft_entries]); - - if (debug_info_level >= DINFO_LEVEL_NORMAL) - generate_new_sfname_entry (); - - ft_entries++; - return filename_table[0].number; -} - -static void -generate_srcinfo_entry (line_entry_num, files_entry_num) - unsigned line_entry_num; - unsigned files_entry_num; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION); - sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL); - sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); -} - -static void -dwarfout_source_line (line, filename) - unsigned int line; - const char *filename; -{ - if (debug_info_level >= DINFO_LEVEL_NORMAL - /* We can't emit line number info for functions in separate sections, - because the assembler can't subtract labels in different sections. */ - && DECL_SECTION_NAME (current_function_decl) == NULL_TREE) - { - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - static unsigned last_line_entry_num = 0; - static unsigned prev_file_entry_num = (unsigned) -1; - unsigned this_file_entry_num; - - function_section (current_function_decl); - sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num); - ASM_OUTPUT_LABEL (asm_out_file, label); - - fputc ('\n', asm_out_file); - - if (use_gnu_debug_info_extensions) - this_file_entry_num = lookup_filename (filename); - else - this_file_entry_num = (unsigned) -1; - - ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); - if (this_file_entry_num != prev_file_entry_num) - { - char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES]; - - sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num); - ASM_OUTPUT_LABEL (asm_out_file, line_entry_label); - } - - { - const char *tail = strrchr (filename, '/'); - - if (tail != NULL) - filename = tail; - } - - dw2_asm_output_data (4, line, "%s:%u", filename, line); - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - if (this_file_entry_num != prev_file_entry_num) - generate_srcinfo_entry (last_line_entry_num, this_file_entry_num); - prev_file_entry_num = this_file_entry_num; - } -} - -/* Generate an entry in the .debug_macinfo section. */ - -static void -generate_macinfo_entry (type, offset, string) - unsigned int type; - rtx offset; - const char *string; -{ - if (! use_gnu_debug_info_extensions) - return; - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); - assemble_integer (gen_rtx_PLUS (SImode, GEN_INT (type << 24), offset), - 4, BITS_PER_UNIT, 1); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string); - ASM_OUTPUT_POP_SECTION (asm_out_file); -} - -/* Wrapper for toplev.c callback to check debug info level. */ -static void -dwarfout_start_source_file_check (line, filename) - unsigned int line; - const char *filename; -{ - if (debug_info_level == DINFO_LEVEL_VERBOSE) - dwarfout_start_source_file (line, filename); -} - -static void -dwarfout_start_source_file (line, filename) - unsigned int line ATTRIBUTE_UNUSED; - const char *filename; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - const char *label1, *label2; - - sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename)); - label1 = (*label == '*') + label; - label2 = (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL; - generate_macinfo_entry (MACINFO_start, - gen_rtx_MINUS (Pmode, - gen_rtx_SYMBOL_REF (Pmode, label1), - gen_rtx_SYMBOL_REF (Pmode, label2)), - ""); -} - -/* Wrapper for toplev.c callback to check debug info level. */ -static void -dwarfout_end_source_file_check (lineno) - unsigned lineno; -{ - if (debug_info_level == DINFO_LEVEL_VERBOSE) - dwarfout_end_source_file (lineno); -} - -static void -dwarfout_end_source_file (lineno) - unsigned lineno; -{ - generate_macinfo_entry (MACINFO_resume, GEN_INT (lineno), ""); -} - -/* Called from check_newline in c-parse.y. The `buffer' parameter - contains the tail part of the directive line, i.e. the part which - is past the initial whitespace, #, whitespace, directive-name, - whitespace part. */ - -static void -dwarfout_define (lineno, buffer) - unsigned lineno; - const char *buffer; -{ - static int initialized = 0; - - if (!initialized) - { - dwarfout_start_source_file (0, primary_filename); - initialized = 1; - } - generate_macinfo_entry (MACINFO_define, GEN_INT (lineno), buffer); -} - -/* Called from check_newline in c-parse.y. The `buffer' parameter - contains the tail part of the directive line, i.e. the part which - is past the initial whitespace, #, whitespace, directive-name, - whitespace part. */ - -static void -dwarfout_undef (lineno, buffer) - unsigned lineno; - const char *buffer; -{ - generate_macinfo_entry (MACINFO_undef, GEN_INT (lineno), buffer); -} - -/* Set up for Dwarf output at the start of compilation. */ - -static void -dwarfout_init (main_input_filename) - const char *main_input_filename; -{ - warning ("support for the DWARF1 debugging format is deprecated"); - - /* Remember the name of the primary input file. */ - - primary_filename = main_input_filename; - - /* Allocate the initial hunk of the pending_sibling_stack. */ - - pending_sibling_stack - = (unsigned *) - xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned)); - pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT; - pending_siblings = 1; - - /* Allocate the initial hunk of the filename_table. */ - - filename_table - = (filename_entry *) - xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry)); - ft_entries_allocated = FT_ENTRIES_INCREMENT; - ft_entries = 0; - - /* Allocate the initial hunk of the pending_types_list. */ - - pending_types_list - = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree)); - pending_types_allocated = PENDING_TYPES_INCREMENT; - pending_types = 0; - - /* Create an artificial RECORD_TYPE node which we can use in our hack - to get the DIEs representing types of formal parameters to come out - only *after* the DIEs for the formal parameters themselves. */ - - fake_containing_scope = make_node (RECORD_TYPE); - - /* Output a starting label for the .text section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - /* Output a starting label for the .data section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - -#if 0 /* GNU C doesn't currently use .data1. */ - /* Output a starting label for the .data1 section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); -#endif - - /* Output a starting label for the .rodata section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - -#if 0 /* GNU C doesn't currently use .rodata1. */ - /* Output a starting label for the .rodata1 section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); -#endif - - /* Output a starting label for the .bss section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - if (debug_info_level >= DINFO_LEVEL_NORMAL) - { - if (use_gnu_debug_info_extensions) - { - /* Output a starting label and an initial (compilation directory) - entry for the .debug_sfnames section. The starting label will be - referenced by the initial entry in the .debug_srcinfo section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION); - ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL); - { - const char *pwd = getpwd (); - char *dirname; - - if (!pwd) - fatal_io_error ("can't get current directory"); - - dirname = concat (pwd, "/", NULL); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname); - free (dirname); - } - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - if (debug_info_level >= DINFO_LEVEL_VERBOSE - && use_gnu_debug_info_extensions) - { - /* Output a starting label for the .debug_macinfo section. This - label will be referenced by the AT_mac_info attribute in the - TAG_compile_unit DIE. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); - ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - /* Generate the initial entry for the .line section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); - ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - if (use_gnu_debug_info_extensions) - { - /* Generate the initial entry for the .debug_srcinfo section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION); - ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL); -#ifdef DWARF_TIMESTAMPS - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL)); -#else - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); -#endif - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - /* Generate the initial entry for the .debug_pubnames section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - /* Generate the initial entry for the .debug_aranges section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, - DEBUG_ARANGES_END_LABEL, - DEBUG_ARANGES_BEGIN_LABEL); - ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1); - ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - /* Setup first DIE number == 1. */ - NEXT_DIE_NUM = next_unused_dienum++; - - /* Generate the initial DIE for the .debug section. Note that the - (string) value given in the AT_name attribute of the TAG_compile_unit - DIE will (typically) be a relative pathname and that this pathname - should be taken as being relative to the directory from which the - compiler was invoked when the given (base) source file was compiled. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); - ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL); - output_die (output_compile_unit_die, (PTR) main_input_filename); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - fputc ('\n', asm_out_file); -} - -/* Output stuff that dwarf requires at the end of every file. */ - -static void -dwarfout_finish (main_input_filename) - const char *main_input_filename ATTRIBUTE_UNUSED; -{ - char label[MAX_ARTIFICIAL_LABEL_BYTES]; - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); - retry_incomplete_types (); - fputc ('\n', asm_out_file); - - /* Mark the end of the chain of siblings which represent all file-scope - declarations in this compilation unit. */ - - /* The (null) DIE which represents the terminator for the (sibling linked) - list of file-scope items is *special*. Normally, we would just call - end_sibling_chain at this point in order to output a word with the - value `4' and that word would act as the terminator for the list of - DIEs describing file-scope items. Unfortunately, if we were to simply - do that, the label that would follow this DIE in the .debug section - (i.e. `..D2') would *not* be properly aligned (as it must be on some - machines) to a 4 byte boundary. - - In order to force the label `..D2' to get aligned to a 4 byte boundary, - the trick used is to insert extra (otherwise useless) padding bytes - into the (null) DIE that we know must precede the ..D2 label in the - .debug section. The amount of padding required can be anywhere between - 0 and 3 bytes. The length word at the start of this DIE (i.e. the one - with the padding) would normally contain the value 4, but now it will - also have to include the padding bytes, so it will instead have some - value in the range 4..7. - - Fortunately, the rules of Dwarf say that any DIE whose length word - contains *any* value less than 8 should be treated as a null DIE, so - this trick works out nicely. Clever, eh? Don't give me any credit - (or blame). I didn't think of this scheme. I just conformed to it. - */ - - output_die (output_padded_null_die, (void *) 0); - dienum_pop (); - - sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); - ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */ - ASM_OUTPUT_POP_SECTION (asm_out_file); - - /* Output a terminator label for the .text section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - /* Output a terminator label for the .data section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - -#if 0 /* GNU C doesn't currently use .data1. */ - /* Output a terminator label for the .data1 section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); -#endif - - /* Output a terminator label for the .rodata section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - -#if 0 /* GNU C doesn't currently use .rodata1. */ - /* Output a terminator label for the .rodata1 section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); -#endif - - /* Output a terminator label for the .bss section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME); - ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - if (debug_info_level >= DINFO_LEVEL_NORMAL) - { - /* Output a terminating entry for the .line section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); - ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); - ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); - ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - if (use_gnu_debug_info_extensions) - { - /* Output a terminating entry for the .debug_srcinfo section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, - LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - if (debug_info_level >= DINFO_LEVEL_VERBOSE) - { - /* Output terminating entries for the .debug_macinfo section. */ - - dwarfout_end_source_file (0); - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - /* Generate the terminating entry for the .debug_pubnames section. */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); - ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); - ASM_OUTPUT_POP_SECTION (asm_out_file); - - /* Generate the terminating entries for the .debug_aranges section. - - Note that we want to do this only *after* we have output the end - labels (for the various program sections) which we are going to - refer to here. This allows us to work around a bug in the m68k - svr4 assembler. That assembler gives bogus assembly-time errors - if (within any given section) you try to take the difference of - two relocatable symbols, both of which are located within some - other section, and if one (or both?) of the symbols involved is - being forward-referenced. By generating the .debug_aranges - entries at this late point in the assembly output, we skirt the - issue simply by avoiding forward-references. - */ - - fputc ('\n', asm_out_file); - ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); - - ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); - - ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL); - -#if 0 /* GNU C doesn't currently use .data1. */ - ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL, - DATA1_BEGIN_LABEL); -#endif - - ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL, - RODATA_BEGIN_LABEL); - -#if 0 /* GNU C doesn't currently use .rodata1. */ - ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL, - RODATA1_BEGIN_LABEL); -#endif - - ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL); - ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL); - - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); - ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); - - ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL); - ASM_OUTPUT_POP_SECTION (asm_out_file); - } - - /* There should not be any pending types left at the end. We need - this now because it may not have been checked on the last call to - dwarfout_file_scope_decl. */ - if (pending_types != 0) - abort (); -} - -#endif /* DWARF_DEBUGGING_INFO */ diff --git a/contrib/gcc/f/g77spec.c b/contrib/gcc/f/g77spec.c deleted file mode 100644 index 449f299..0000000 --- a/contrib/gcc/f/g77spec.c +++ /dev/null @@ -1,568 +0,0 @@ -/* Specific flags and argument handling of the Fortran front-end. - Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2006 - Free Software Foundation, Inc. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to -the Free Software Foundation, 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -/* This file contains a filter for the main `gcc' driver, which is - replicated for the `g77' driver by adding this filter. The purpose - of this filter is to be basically identical to gcc (in that - it faithfully passes all of the original arguments to gcc) but, - unless explicitly overridden by the user in certain ways, ensure - that the needs of the language supported by this wrapper are met. - - For GNU Fortran (g77), we do the following to the argument list - before passing it to `gcc': - - 1. Make sure `-lg2c -lm' is at the end of the list. - - 2. Make sure each time `-lg2c' or `-lm' is seen, it forms - part of the series `-lg2c -lm'. - - #1 and #2 are not done if `-nostdlib' or any option that disables - the linking phase is present, or if `-xfoo' is in effect. Note that - a lack of source files or -l options disables linking. - - This program was originally made out of gcc/cp/g++spec.c, but the - way it builds the new argument list was rewritten so it is much - easier to maintain, improve the way it decides to add or not add - extra arguments, etc. And several improvements were made in the - handling of arguments, primarily to make it more consistent with - `gcc' itself. */ - -#include "config.h" -#include "system.h" -#include "coretypes.h" -#include "tm.h" -#include "gcc.h" -#include "intl.h" - -#ifndef MATH_LIBRARY -#define MATH_LIBRARY "-lm" -#endif -#ifndef MATH_LIBRARY_PROFILE -#define MATH_LIBRARY_PROFILE "-lm" -#endif - -#ifndef FORTRAN_INIT -#define FORTRAN_INIT "-lfrtbegin" -#endif -#ifndef FORTRAN_INIT_PROFILE -#define FORTRAN_INIT_PROFILE "-lfrtbegin" -#endif - -#ifndef FORTRAN_LIBRARY -#define FORTRAN_LIBRARY "-lg2c" -#endif -#ifndef FORTRAN_LIBRARY_PROFILE -#define FORTRAN_LIBRARY_PROFILE "-lg2c" -#endif - -/* Options this driver needs to recognize, not just know how to - skip over. */ -typedef enum -{ - OPTION_b, /* Aka --prefix. */ - OPTION_B, /* Aka --target. */ - OPTION_c, /* Aka --compile. */ - OPTION_driver, /* Wrapper-specific option. */ - OPTION_E, /* Aka --preprocess. */ - OPTION_help, /* --help. */ - OPTION_i, /* -imacros, -include, -include-*. */ - OPTION_l, - OPTION_L, /* Aka --library-directory. */ - OPTION_M, /* Aka --dependencies. */ - OPTION_MM, /* Aka --user-dependencies. */ - OPTION_nostdlib, /* Aka --no-standard-libraries, or - -nodefaultlibs. */ - OPTION_o, /* Aka --output. */ - OPTION_p, /* Aka --profile. */ - OPTION_S, /* Aka --assemble. */ - OPTION_syntax_only, /* -fsyntax-only. */ - OPTION_v, /* Aka --verbose. */ - OPTION_version, /* --version. */ - OPTION_V, /* Aka --use-version. */ - OPTION_x, /* Aka --language. */ - OPTION_ /* Unrecognized or unimportant. */ -} Option; - -/* The original argument list and related info is copied here. */ -static int g77_xargc; -static const char *const *g77_xargv; -static void lookup_option (Option *, int *, const char **, const char *); -static void append_arg (const char *); - -/* The new argument list will be built here. */ -static int g77_newargc; -static const char **g77_newargv; - -#ifndef SWITCH_TAKES_ARG -#define SWITCH_TAKES_ARG(CHAR) DEFAULT_SWITCH_TAKES_ARG(CHAR) -#endif - -#ifndef WORD_SWITCH_TAKES_ARG -#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR) -#endif - -/* Assumes text[0] == '-'. Returns number of argv items that belong to - (and follow) this one, an option id for options important to the - caller, and a pointer to the first char of the arg, if embedded (else - returns NULL, meaning no arg or it's the next argv). - - Note that this also assumes gcc.c's pass converting long options - to short ones, where available, has already been run. */ - -static void -lookup_option (Option *xopt, int *xskip, const char **xarg, const char *text) -{ - Option opt = OPTION_; - int skip; - const char *arg = NULL; - - if ((skip = SWITCH_TAKES_ARG (text[1]))) - skip -= (text[2] != '\0'); /* See gcc.c. */ - - if (text[1] == 'B') - opt = OPTION_B, skip = (text[2] == '\0'), arg = text + 2; - else if (text[1] == 'b') - opt = OPTION_b, skip = (text[2] == '\0'), arg = text + 2; - else if ((text[1] == 'c') && (text[2] == '\0')) - opt = OPTION_c, skip = 0; - else if ((text[1] == 'E') && (text[2] == '\0')) - opt = OPTION_E, skip = 0; - else if (text[1] == 'i') - opt = OPTION_i, skip = 0; - else if (text[1] == 'l') - opt = OPTION_l; - else if (text[1] == 'L') - opt = OPTION_L, arg = text + 2; - else if (text[1] == 'o') - opt = OPTION_o; - else if ((text[1] == 'p') && (text[2] == '\0') - || (text[1] == 'p') && (text[2] == 'g') && (text[3] == '\0')) - opt = OPTION_p; - else if ((text[1] == 'S') && (text[2] == '\0')) - opt = OPTION_S, skip = 0; - else if (text[1] == 'V') - opt = OPTION_V, skip = (text[2] == '\0'); - else if ((text[1] == 'v') && (text[2] == '\0')) - opt = OPTION_v, skip = 0; - else if (text[1] == 'x') - opt = OPTION_x, arg = text + 2; - else - { - if ((skip = WORD_SWITCH_TAKES_ARG (text + 1)) != 0) /* See gcc.c. */ - ; - else if (! strncmp (text, "-fdriver", 8)) /* Really --driver!! */ - opt = OPTION_driver; /* Never mind arg, this is unsupported. */ - else if (! strcmp (text, "-fhelp")) /* Really --help!! */ - opt = OPTION_help; - else if (! strcmp (text, "-M")) - opt = OPTION_M; - else if (! strcmp (text, "-MM")) - opt = OPTION_MM; - else if (! strcmp (text, "-nostdlib") - || ! strcmp (text, "-nodefaultlibs")) - opt = OPTION_nostdlib; - else if (! strcmp (text, "-fsyntax-only")) - opt = OPTION_syntax_only; - else if (! strcmp (text, "-dumpversion")) - opt = OPTION_version; - else if (! strcmp (text, "-fversion")) /* Really --version!! */ - opt = OPTION_version; - else if (! strcmp (text, "-Xlinker") - || ! strcmp (text, "-specs")) - skip = 1; - else - skip = 0; - } - - if (xopt != NULL) - *xopt = opt; - if (xskip != NULL) - *xskip = skip; - if (xarg != NULL) - { - if ((arg != NULL) - && (arg[0] == '\0')) - *xarg = NULL; - else - *xarg = arg; - } -} - -/* Append another argument to the list being built. As long as it is - identical to the corresponding arg in the original list, just increment - the new arg count. Otherwise allocate a new list, etc. */ - -static void -append_arg (const char *arg) -{ - static int newargsize; - -#if 0 - fprintf (stderr, "`%s'\n", arg); -#endif - - if (g77_newargv == g77_xargv - && g77_newargc < g77_xargc - && (arg == g77_xargv[g77_newargc] - || ! strcmp (arg, g77_xargv[g77_newargc]))) - { - ++g77_newargc; - return; /* Nothing new here. */ - } - - if (g77_newargv == g77_xargv) - { /* Make new arglist. */ - int i; - - newargsize = (g77_xargc << 2) + 20; /* This should handle all. */ - g77_newargv = xmalloc (newargsize * sizeof (char *)); - - /* Copy what has been done so far. */ - for (i = 0; i < g77_newargc; ++i) - g77_newargv[i] = g77_xargv[i]; - } - - if (g77_newargc == newargsize) - fatal ("overflowed output arg list for `%s'", arg); - - g77_newargv[g77_newargc++] = arg; -} - -void -lang_specific_driver (int *in_argc, const char *const **in_argv, - int *in_added_libraries ATTRIBUTE_UNUSED) -{ - int argc = *in_argc; - const char *const *argv = *in_argv; - int i; - int verbose = 0; - Option opt; - int skip; - const char *arg; - - /* This will be NULL if we encounter a situation where we should not - link in libf2c. */ - const char *library = FORTRAN_LIBRARY; - - /* 0 => -xnone in effect. - 1 => -xfoo in effect. */ - int saw_speclang = 0; - - /* 0 => initial/reset state - 1 => last arg was -l<library> - 2 => last two args were -l<library> -lm. */ - int saw_library = 0; - - /* 0 => initial/reset state - 1 => FORTRAN_INIT linked in */ - int use_init = 0; - /* By default, we throw on the math library if we have one. */ - int need_math = (MATH_LIBRARY[0] != '\0'); - - /* If non-zero, the user gave us the `-p' or `-pg' flag. */ - int saw_profile_flag = 0; - - /* The number of input and output files in the incoming arg list. */ - int n_infiles = 0; - int n_outfiles = 0; - -#if 0 - fprintf (stderr, "Incoming:"); - for (i = 0; i < argc; i++) - fprintf (stderr, " %s", argv[i]); - fprintf (stderr, "\n"); -#endif - - g77_xargc = argc; - g77_xargv = argv; - g77_newargc = 0; - g77_newargv = (const char **) argv; - - /* First pass through arglist. - - If -nostdlib or a "turn-off-linking" option is anywhere in the - command line, don't do any library-option processing (except - relating to -x). Also, if -v is specified, but no other options - that do anything special (allowing -V version, etc.), remember - to add special stuff to make gcc command actually invoke all - the different phases of the compilation process so all the version - numbers can be seen. - - Also, here is where all problems with missing arguments to options - are caught. If this loop is exited normally, it means all options - have the appropriate number of arguments as far as the rest of this - program is concerned. */ - - for (i = 1; i < argc; ++i) - { - if ((argv[i][0] == '+') && (argv[i][1] == 'e')) - { - continue; - } - - if ((argv[i][0] != '-') || (argv[i][1] == '\0')) - { - ++n_infiles; - continue; - } - - lookup_option (&opt, &skip, NULL, argv[i]); - - switch (opt) - { - case OPTION_nostdlib: - case OPTION_c: - case OPTION_S: - case OPTION_syntax_only: - case OPTION_E: - case OPTION_M: - case OPTION_MM: - /* These options disable linking entirely or linking of the - standard libraries. */ - library = 0; - break; - - case OPTION_l: - ++n_infiles; - break; - - case OPTION_o: - ++n_outfiles; - break; - - case OPTION_p: - saw_profile_flag = 1; - library = FORTRAN_LIBRARY_PROFILE; - break; - - case OPTION_v: - verbose = 1; - break; - - case OPTION_b: - case OPTION_B: - case OPTION_L: - case OPTION_i: - case OPTION_V: - /* These options are useful in conjunction with -v to get - appropriate version info. */ - break; - - case OPTION_version: - printf ("GNU Fortran (GCC) %s\n", version_string); - printf ("Copyright %s 2006 Free Software Foundation, Inc.\n", - _("(C)")); - printf ("\n"); - printf (_("\ -GNU Fortran comes with NO WARRANTY, to the extent permitted by law.\n\ -You may redistribute copies of GNU Fortran\n\ -under the terms of the GNU General Public License.\n\ -For more information about these matters, see the file named COPYING\n\ -or type the command `info -f g77 Copying'.\n\ -")); - exit (0); - break; - - case OPTION_help: - /* Let gcc.c handle this, as it has a really - cool facility for handling --help and --verbose --help. */ - return; - - case OPTION_driver: - fatal ("--driver no longer supported"); - break; - - default: - break; - } - - /* This is the one place we check for missing arguments in the - program. */ - - if (i + skip < argc) - i += skip; - else - fatal ("argument to `%s' missing", argv[i]); - } - - if ((n_outfiles != 0) && (n_infiles == 0)) - fatal ("no input files; unwilling to write output files"); - - /* If there are no input files, no need for the library. */ - if (n_infiles == 0) - library = 0; - - /* Second pass through arglist, transforming arguments as appropriate. */ - - append_arg (argv[0]); /* Start with command name, of course. */ - - for (i = 1; i < argc; ++i) - { - if (argv[i][0] == '\0') - { - append_arg (argv[i]); /* Interesting. Just append as is. */ - continue; - } - - if ((argv[i][0] == '-') && (argv[i][1] != 'l')) - { - /* Not a filename or library. */ - - if (saw_library == 1 && need_math) /* -l<library>. */ - append_arg (saw_profile_flag ? MATH_LIBRARY_PROFILE : MATH_LIBRARY); - - saw_library = 0; - - lookup_option (&opt, &skip, &arg, argv[i]); - - if (argv[i][1] == '\0') - { - append_arg (argv[i]); /* "-" == Standard input. */ - continue; - } - - if (opt == OPTION_x) - { - /* Track input language. */ - const char *lang; - - if (arg == NULL) - lang = argv[i+1]; - else - lang = arg; - - saw_speclang = (strcmp (lang, "none") != 0); - } - - append_arg (argv[i]); - - for (; skip != 0; --skip) - append_arg (argv[++i]); - - continue; - } - - /* A filename/library, not an option. */ - - if (saw_speclang) - saw_library = 0; /* -xfoo currently active. */ - else - { /* -lfoo or filename. */ - if (strcmp (argv[i], MATH_LIBRARY) == 0) - { - if (saw_library == 1) - saw_library = 2; /* -l<library> -lm. */ - else - { - if (0 == use_init) - { - append_arg (saw_profile_flag ? FORTRAN_INIT_PROFILE - : FORTRAN_INIT); - use_init = 1; - } - append_arg (saw_profile_flag ? FORTRAN_LIBRARY_PROFILE - : FORTRAN_LIBRARY); - } - } - else if (strcmp (argv[i], FORTRAN_LIBRARY) == 0) - saw_library = 1; /* -l<library>. */ - else - { /* Other library, or filename. */ - if (saw_library == 1 && need_math) - append_arg (saw_profile_flag ? MATH_LIBRARY_PROFILE - : MATH_LIBRARY); - saw_library = 0; - } - } - append_arg (argv[i]); - } - - /* Append `-lg2c -lm' as necessary. */ - - if (library) - { /* Doing a link and no -nostdlib. */ - if (saw_speclang) - append_arg ("-xnone"); - - switch (saw_library) - { - case 0: - if (0 == use_init) - { - append_arg (saw_profile_flag ? FORTRAN_INIT_PROFILE - : FORTRAN_INIT); - use_init = 1; - } - append_arg (library); - case 1: - if (need_math) - append_arg (saw_profile_flag ? MATH_LIBRARY_PROFILE : MATH_LIBRARY); - default: - break; - } - } - -#ifdef ENABLE_SHARED_LIBGCC - if (library) - { - int i; - - for (i = 1; i < g77_newargc; i++) - if (g77_newargv[i][0] == '-') - if (strcmp (g77_newargv[i], "-static-libgcc") == 0 - || strcmp (g77_newargv[i], "-static") == 0) - break; - - if (i == g77_newargc) - append_arg ("-shared-libgcc"); - } - -#endif - - if (verbose - && g77_newargv != g77_xargv) - { - fprintf (stderr, "Driving:"); - for (i = 0; i < g77_newargc; i++) - fprintf (stderr, " %s", g77_newargv[i]); - fprintf (stderr, "\n"); - } - - *in_argc = g77_newargc; - *in_argv = g77_newargv; -} - -/* Called before linking. Returns 0 on success and -1 on failure. */ -int lang_specific_pre_link (void) /* Not used for F77. */ -{ - return 0; -} - -/* Number of extra output files that lang_specific_pre_link may generate. */ -int lang_specific_extra_outfiles = 0; /* Not used for F77. */ - -/* Table of language-specific spec functions. */ -const struct spec_function lang_specific_spec_functions[] = -{ - { 0, 0 } -}; diff --git a/contrib/gcc/make-temp-file.c b/contrib/gcc/make-temp-file.c deleted file mode 100644 index 563bd46..0000000 --- a/contrib/gcc/make-temp-file.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Utility to pick a temporary filename prefix. - Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc. - -This file is part of the libiberty library. -Libiberty is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -Libiberty is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If not, -write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> /* May get P_tmpdir. */ -#include <sys/types.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_SYS_FILE_H -#include <sys/file.h> /* May get R_OK, etc. on some systems. */ -#endif - -#ifndef R_OK -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -#endif - -#include "libiberty.h" -extern int mkstemps PARAMS ((char *, int)); - -/* '/' works just fine on MS-DOS based systems. */ -#ifndef DIR_SEPARATOR -#define DIR_SEPARATOR '/' -#endif - -/* Name of temporary file. - mktemp requires 6 trailing X's. */ -#define TEMP_FILE "ccXXXXXX" -#define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1) - -/* Subroutine of choose_tmpdir. - If BASE is non-NULL, return it. - Otherwise it checks if DIR is a usable directory. - If success, DIR is returned. - Otherwise NULL is returned. */ - -static inline const char *try PARAMS ((const char *, const char *)); - -static inline const char * -try (dir, base) - const char *dir, *base; -{ - if (base != 0) - return base; - if (dir != 0 - && access (dir, R_OK | W_OK | X_OK) == 0) - return dir; - return 0; -} - -static const char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 }; -static const char usrtmp[] = -{ DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 }; -static const char vartmp[] = -{ DIR_SEPARATOR, 'v', 'a', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 }; - -static char *memoized_tmpdir; - -/* - -@deftypefn Replacement char* choose_tmpdir () - -Returns a pointer to a directory path suitable for creating temporary -files in. - -@end deftypefn - -*/ - -char * -choose_tmpdir () -{ - const char *base = 0; - char *tmpdir; - unsigned int len; - - if (memoized_tmpdir) - return memoized_tmpdir; - - base = try (getenv ("TMPDIR"), base); - base = try (getenv ("TMP"), base); - base = try (getenv ("TEMP"), base); - -#ifdef P_tmpdir - base = try (P_tmpdir, base); -#endif - - /* Try /tmp, /var/tmp, then /usr/tmp. */ - base = try (tmp, base); - base = try (vartmp, base); - base = try (usrtmp, base); - - /* If all else fails, use the current directory! */ - if (base == 0) - base = "."; - - /* Append DIR_SEPARATOR to the directory we've chosen - and return it. */ - len = strlen (base); - tmpdir = xmalloc (len + 2); - strcpy (tmpdir, base); - tmpdir[len] = DIR_SEPARATOR; - tmpdir[len+1] = '\0'; - - memoized_tmpdir = tmpdir; - return tmpdir; -} - -/* - -@deftypefn Replacement char* make_temp_file (const char *@var{suffix}) - -Return a temporary file name (as a string) or @code{NULL} if unable to -create one. @var{suffix} is a suffix to append to the file name. The -string is @code{malloc}ed, and the temporary file has been created. - -@end deftypefn - -*/ - -char * -make_temp_file (suffix) - const char *suffix; -{ - const char *base = choose_tmpdir (); - char *temp_filename; - int base_len, suffix_len; - int fd; - - if (suffix == 0) - suffix = ""; - - base_len = strlen (base); - suffix_len = strlen (suffix); - - temp_filename = xmalloc (base_len - + TEMP_FILE_LEN - + suffix_len + 1); - strcpy (temp_filename, base); - strcpy (temp_filename + base_len, TEMP_FILE); - strcpy (temp_filename + base_len + TEMP_FILE_LEN, suffix); - - fd = mkstemps (temp_filename, suffix_len); - /* If mkstemps failed, then something bad is happening. Maybe we should - issue a message about a possible security attack in progress? */ - if (fd == -1) - abort (); - /* Similarly if we can not close the file. */ - if (close (fd)) - abort (); - return temp_filename; -} diff --git a/contrib/gcc/pexecute.c b/contrib/gcc/pexecute.c deleted file mode 100644 index 0f232ca..0000000 --- a/contrib/gcc/pexecute.c +++ /dev/null @@ -1,794 +0,0 @@ -/* Utilities to execute a program in a subprocess (possibly linked by pipes - with other subprocesses), and wait for it. - Copyright (C) 1996-2000 Free Software Foundation, Inc. - -This file is part of the libiberty library. -Libiberty is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -Libiberty is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If not, -write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ - -/* $FreeBSD$ */ - -/* This file exports two functions: pexecute and pwait. */ - -/* This file lives in at least two places: libiberty and gcc. - Don't change one without the other. */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <errno.h> -#ifdef NEED_DECLARATION_ERRNO -extern int errno; -#endif -#ifdef HAVE_STRING_H -#include <string.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#ifdef HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif - -#include "libiberty.h" -#include "safe-ctype.h" - -/* stdin file number. */ -#define STDIN_FILE_NO 0 - -/* stdout file number. */ -#define STDOUT_FILE_NO 1 - -/* value of `pipe': port index for reading. */ -#define READ_PORT 0 - -/* value of `pipe': port index for writing. */ -#define WRITE_PORT 1 - -static char *install_error_msg = "installation problem, cannot exec `%s'"; - -/* pexecute: execute a program. - -@deftypefn Extension int pexecute (const char *@var{program}, char * const *@var{argv}, const char *@var{this_pname}, const char *@var{temp_base}, char **@var{errmsg_fmt}, char **@var{errmsg_arg}, int flags) - -Executes a program. - -@var{program} and @var{argv} are the arguments to -@code{execv}/@code{execvp}. - -@var{this_pname} is name of the calling program (i.e., @code{argv[0]}). - -@var{temp_base} is the path name, sans suffix, of a temporary file to -use if needed. This is currently only needed for MS-DOS ports that -don't use @code{go32} (do any still exist?). Ports that don't need it -can pass @code{NULL}. - -(@code{@var{flags} & PEXECUTE_SEARCH}) is non-zero if @env{PATH} should be searched -(??? It's not clear that GCC passes this flag correctly). (@code{@var{flags} & -PEXECUTE_FIRST}) is nonzero for the first process in chain. -(@code{@var{flags} & PEXECUTE_FIRST}) is nonzero for the last process -in chain. The first/last flags could be simplified to only mark the -last of a chain of processes but that requires the caller to always -mark the last one (and not give up early if some error occurs). -It's more robust to require the caller to mark both ends of the chain. - -The result is the pid on systems like Unix where we -@code{fork}/@code{exec} and on systems like WIN32 and OS/2 where we -use @code{spawn}. It is up to the caller to wait for the child. - -The result is the @code{WEXITSTATUS} on systems like MS-DOS where we -@code{spawn} and wait for the child here. - -Upon failure, @var{errmsg_fmt} and @var{errmsg_arg} are set to the -text of the error message with an optional argument (if not needed, -@var{errmsg_arg} is set to @code{NULL}), and @minus{}1 is returned. -@code{errno} is available to the caller to use. - -@end deftypefn - -@deftypefn Extension int pwait (int @var{pid}, int *@var{status}, int @var{flags}) - -Waits for a program started by @code{pexecute} to finish. - -@var{pid} is the process id of the task to wait for. @var{status} is -the `status' argument to wait. @var{flags} is currently unused (allows -future enhancement without breaking upward compatibility). Pass 0 for now. - -The result is the pid of the child reaped, or -1 for failure -(@code{errno} says why). - -On systems that don't support waiting for a particular child, @var{pid} is -ignored. On systems like MS-DOS that don't really multitask @code{pwait} -is just a mechanism to provide a consistent interface for the caller. - -@end deftypefn - -@undocumented pfinish - - pfinish: finish generation of script - - pfinish is necessary for systems like MPW where a script is generated that - runs the requested programs. */ - -#ifdef __MSDOS__ - -/* MSDOS doesn't multitask, but for the sake of a consistent interface - the code behaves like it does. pexecute runs the program, tucks the - exit code away, and returns a "pid". pwait must be called to fetch the - exit code. */ - -#include <process.h> - -/* For communicating information from pexecute to pwait. */ -static int last_pid = 0; -static int last_status = 0; -static int last_reaped = 0; - -int -pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) - const char *program; - char * const *argv; - const char *this_pname; - const char *temp_base; - char **errmsg_fmt, **errmsg_arg; - int flags; -{ - int rc; - - last_pid++; - if (last_pid < 0) - last_pid = 1; - - if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE) - abort (); - -#ifdef __DJGPP__ - /* ??? What are the possible return values from spawnv? */ - rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_WAIT, program, argv); -#else - char *scmd, *rf; - FILE *argfile; - int i, el = flags & PEXECUTE_SEARCH ? 4 : 0; - - if (temp_base == 0) - temp_base = choose_temp_base (); - scmd = (char *) xmalloc (strlen (program) + strlen (temp_base) + 6 + el); - rf = scmd + strlen(program) + 2 + el; - sprintf (scmd, "%s%s @%s.gp", program, - (flags & PEXECUTE_SEARCH ? ".exe" : ""), temp_base); - argfile = fopen (rf, "w"); - if (argfile == 0) - { - int errno_save = errno; - free (scmd); - errno = errno_save; - *errmsg_fmt = "cannot open `%s.gp'"; - *errmsg_arg = temp_base; - return -1; - } - - for (i=1; argv[i]; i++) - { - char *cp; - for (cp = argv[i]; *cp; cp++) - { - if (*cp == '"' || *cp == '\'' || *cp == '\\' || ISSPACE (*cp)) - fputc ('\\', argfile); - fputc (*cp, argfile); - } - fputc ('\n', argfile); - } - fclose (argfile); - - rc = system (scmd); - - { - int errno_save = errno; - remove (rf); - free (scmd); - errno = errno_save; - } -#endif - - if (rc == -1) - { - *errmsg_fmt = install_error_msg; - *errmsg_arg = (char *)program; - return -1; - } - - /* Tuck the status away for pwait, and return a "pid". */ - last_status = rc << 8; - return last_pid; -} - -/* Use ECHILD if available, otherwise use EINVAL. */ -#ifdef ECHILD -#define PWAIT_ERROR ECHILD -#else -#define PWAIT_ERROR EINVAL -#endif - -int -pwait (pid, status, flags) - int pid; - int *status; - int flags; -{ - /* On MSDOS each pexecute must be followed by it's associated pwait. */ - if (pid != last_pid - /* Called twice for the same child? */ - || pid == last_reaped) - { - errno = PWAIT_ERROR; - return -1; - } - /* ??? Here's an opportunity to canonicalize the values in STATUS. - Needed? */ -#ifdef __DJGPP__ - *status = (last_status >> 8); -#else - *status = last_status; -#endif - last_reaped = last_pid; - return last_pid; -} - -#endif /* MSDOS */ - -#if defined (_WIN32) && ! defined (_UWIN) - -#include <process.h> - -#ifdef __CYGWIN__ - -#define fix_argv(argvec) (argvec) - -extern int _spawnv (); -extern int _spawnvp (); - -#else /* ! __CYGWIN__ */ - -/* This is a kludge to get around the Microsoft C spawn functions' propensity - to remove the outermost set of double quotes from all arguments. */ - -static const char * const * -fix_argv (argvec) - char **argvec; -{ - int i; - - for (i = 1; argvec[i] != 0; i++) - { - int len, j; - char *temp, *newtemp; - - temp = argvec[i]; - len = strlen (temp); - for (j = 0; j < len; j++) - { - if (temp[j] == '"') - { - newtemp = xmalloc (len + 2); - strncpy (newtemp, temp, j); - newtemp [j] = '\\'; - strncpy (&newtemp [j+1], &temp [j], len-j); - newtemp [len+1] = 0; - temp = newtemp; - len++; - j++; - } - } - - argvec[i] = temp; - } - - for (i = 0; argvec[i] != 0; i++) - { - if (strpbrk (argvec[i], " \t")) - { - int len, trailing_backslash; - char *temp; - - len = strlen (argvec[i]); - trailing_backslash = 0; - - /* There is an added complication when an arg with embedded white - space ends in a backslash (such as in the case of -iprefix arg - passed to cpp). The resulting quoted strings gets misinterpreted - by the command interpreter -- it thinks that the ending quote - is escaped by the trailing backslash and things get confused. - We handle this case by escaping the trailing backslash, provided - it was not escaped in the first place. */ - if (len > 1 - && argvec[i][len-1] == '\\' - && argvec[i][len-2] != '\\') - { - trailing_backslash = 1; - ++len; /* to escape the final backslash. */ - } - - len += 2; /* and for the enclosing quotes. */ - - temp = xmalloc (len + 1); - temp[0] = '"'; - strcpy (temp + 1, argvec[i]); - if (trailing_backslash) - temp[len-2] = '\\'; - temp[len-1] = '"'; - temp[len] = '\0'; - - argvec[i] = temp; - } - } - - return (const char * const *) argvec; -} -#endif /* __CYGWIN__ */ - -#include <io.h> -#include <fcntl.h> -#include <signal.h> - -/* mingw32 headers may not define the following. */ - -#ifndef _P_WAIT -# define _P_WAIT 0 -# define _P_NOWAIT 1 -# define _P_OVERLAY 2 -# define _P_NOWAITO 3 -# define _P_DETACH 4 - -# define WAIT_CHILD 0 -# define WAIT_GRANDCHILD 1 -#endif - -/* Win32 supports pipes */ -int -pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) - const char *program; - char * const *argv; - const char *this_pname; - const char *temp_base; - char **errmsg_fmt, **errmsg_arg; - int flags; -{ - int pid; - int pdes[2], org_stdin, org_stdout; - int input_desc, output_desc; - int retries, sleep_interval; - - /* Pipe waiting from last process, to be used as input for the next one. - Value is STDIN_FILE_NO if no pipe is waiting - (i.e. the next command is the first of a group). */ - static int last_pipe_input; - - /* If this is the first process, initialize. */ - if (flags & PEXECUTE_FIRST) - last_pipe_input = STDIN_FILE_NO; - - input_desc = last_pipe_input; - - /* If this isn't the last process, make a pipe for its output, - and record it as waiting to be the input to the next process. */ - if (! (flags & PEXECUTE_LAST)) - { - if (_pipe (pdes, 256, O_BINARY) < 0) - { - *errmsg_fmt = "pipe"; - *errmsg_arg = NULL; - return -1; - } - output_desc = pdes[WRITE_PORT]; - last_pipe_input = pdes[READ_PORT]; - } - else - { - /* Last process. */ - output_desc = STDOUT_FILE_NO; - last_pipe_input = STDIN_FILE_NO; - } - - if (input_desc != STDIN_FILE_NO) - { - org_stdin = dup (STDIN_FILE_NO); - dup2 (input_desc, STDIN_FILE_NO); - close (input_desc); - } - - if (output_desc != STDOUT_FILE_NO) - { - org_stdout = dup (STDOUT_FILE_NO); - dup2 (output_desc, STDOUT_FILE_NO); - close (output_desc); - } - - pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv) - (_P_NOWAIT, program, fix_argv(argv)); - - if (input_desc != STDIN_FILE_NO) - { - dup2 (org_stdin, STDIN_FILE_NO); - close (org_stdin); - } - - if (output_desc != STDOUT_FILE_NO) - { - dup2 (org_stdout, STDOUT_FILE_NO); - close (org_stdout); - } - - if (pid == -1) - { - *errmsg_fmt = install_error_msg; - *errmsg_arg = program; - return -1; - } - - return pid; -} - -/* MS CRTDLL doesn't return enough information in status to decide if the - child exited due to a signal or not, rather it simply returns an - integer with the exit code of the child; eg., if the child exited with - an abort() call and didn't have a handler for SIGABRT, it simply returns - with status = 3. We fix the status code to conform to the usual WIF* - macros. Note that WIFSIGNALED will never be true under CRTDLL. */ - -int -pwait (pid, status, flags) - int pid; - int *status; - int flags; -{ -#ifdef __CYGWIN__ - return wait (status); -#else - int termstat; - - pid = _cwait (&termstat, pid, WAIT_CHILD); - - /* ??? Here's an opportunity to canonicalize the values in STATUS. - Needed? */ - - /* cwait returns the child process exit code in termstat. - A value of 3 indicates that the child caught a signal, but not - which one. Since only SIGABRT, SIGFPE and SIGINT do anything, we - report SIGABRT. */ - if (termstat == 3) - *status = SIGABRT; - else - *status = (((termstat) & 0xff) << 8); - - return pid; -#endif /* __CYGWIN__ */ -} - -#endif /* _WIN32 && ! _UWIN */ - -#ifdef OS2 - -/* ??? Does OS2 have process.h? */ -extern int spawnv (); -extern int spawnvp (); - -int -pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) - const char *program; - char * const *argv; - const char *this_pname; - const char *temp_base; - char **errmsg_fmt, **errmsg_arg; - int flags; -{ - int pid; - - if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE) - abort (); - /* ??? Presumably 1 == _P_NOWAIT. */ - pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (1, program, argv); - if (pid == -1) - { - *errmsg_fmt = install_error_msg; - *errmsg_arg = program; - return -1; - } - return pid; -} - -int -pwait (pid, status, flags) - int pid; - int *status; - int flags; -{ - /* ??? Here's an opportunity to canonicalize the values in STATUS. - Needed? */ - int pid = wait (status); - return pid; -} - -#endif /* OS2 */ - -#ifdef MPW - -/* MPW pexecute doesn't actually run anything; instead, it writes out - script commands that, when run, will do the actual executing. - - For example, in GCC's case, GCC will write out several script commands: - - cpp ... - cc1 ... - as ... - ld ... - - and then exit. None of the above programs will have run yet. The task - that called GCC will then execute the script and cause cpp,etc. to run. - The caller must invoke pfinish before calling exit. This adds - the finishing touches to the generated script. */ - -static int first_time = 1; - -int -pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) - const char *program; - char * const *argv; - const char *this_pname; - const char *temp_base; - char **errmsg_fmt, **errmsg_arg; - int flags; -{ - char tmpprogram[255]; - char *cp, *tmpname; - int i; - - mpwify_filename (program, tmpprogram); - if (first_time) - { - printf ("Set Failed 0\n"); - first_time = 0; - } - - fputs ("If {Failed} == 0\n", stdout); - /* If being verbose, output a copy of the command. It should be - accurate enough and escaped enough to be "clickable". */ - if (flags & PEXECUTE_VERBOSE) - { - fputs ("\tEcho ", stdout); - fputc ('\'', stdout); - fputs (tmpprogram, stdout); - fputc ('\'', stdout); - fputc (' ', stdout); - for (i=1; argv[i]; i++) - { - fputc ('\'', stdout); - /* See if we have an argument that needs fixing. */ - if (strchr(argv[i], '/')) - { - tmpname = (char *) xmalloc (256); - mpwify_filename (argv[i], tmpname); - argv[i] = tmpname; - } - for (cp = argv[i]; *cp; cp++) - { - /* Write an Option-d escape char in front of special chars. */ - if (strchr("'+", *cp)) - fputc ('\266', stdout); - fputc (*cp, stdout); - } - fputc ('\'', stdout); - fputc (' ', stdout); - } - fputs ("\n", stdout); - } - fputs ("\t", stdout); - fputs (tmpprogram, stdout); - fputc (' ', stdout); - - for (i=1; argv[i]; i++) - { - /* See if we have an argument that needs fixing. */ - if (strchr(argv[i], '/')) - { - tmpname = (char *) xmalloc (256); - mpwify_filename (argv[i], tmpname); - argv[i] = tmpname; - } - if (strchr (argv[i], ' ')) - fputc ('\'', stdout); - for (cp = argv[i]; *cp; cp++) - { - /* Write an Option-d escape char in front of special chars. */ - if (strchr("'+", *cp)) - fputc ('\266', stdout); - fputc (*cp, stdout); - } - if (strchr (argv[i], ' ')) - fputc ('\'', stdout); - fputc (' ', stdout); - } - - fputs ("\n", stdout); - - /* Output commands that arrange to clean up and exit if a failure occurs. - We have to be careful to collect the status from the program that was - run, rather than some other script command. Also, we don't exit - immediately, since necessary cleanups are at the end of the script. */ - fputs ("\tSet TmpStatus {Status}\n", stdout); - fputs ("\tIf {TmpStatus} != 0\n", stdout); - fputs ("\t\tSet Failed {TmpStatus}\n", stdout); - fputs ("\tEnd\n", stdout); - fputs ("End\n", stdout); - - /* We're just composing a script, can't fail here. */ - return 0; -} - -int -pwait (pid, status, flags) - int pid; - int *status; - int flags; -{ - *status = 0; - return 0; -} - -/* Write out commands that will exit with the correct error code - if something in the script failed. */ - -void -pfinish () -{ - printf ("\tExit \"{Failed}\"\n"); -} - -#endif /* MPW */ - -/* include for Unix-like environments but not for Dos-like environments */ -#if ! defined (__MSDOS__) && ! defined (OS2) && ! defined (MPW) \ - && ! (defined (_WIN32) && ! defined (_UWIN)) - -extern int execv (); -extern int execvp (); - -int -pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) - const char *program; - char * const *argv; - const char *this_pname; - const char *temp_base ATTRIBUTE_UNUSED; - char **errmsg_fmt, **errmsg_arg; - int flags; -{ - int (*func)() = (flags & PEXECUTE_SEARCH ? execvp : execv); - int pid; - int pdes[2]; - int input_desc, output_desc; - int retries, sleep_interval; - /* Pipe waiting from last process, to be used as input for the next one. - Value is STDIN_FILE_NO if no pipe is waiting - (i.e. the next command is the first of a group). */ - static int last_pipe_input; - - /* If this is the first process, initialize. */ - if (flags & PEXECUTE_FIRST) - last_pipe_input = STDIN_FILE_NO; - - input_desc = last_pipe_input; - - /* If this isn't the last process, make a pipe for its output, - and record it as waiting to be the input to the next process. */ - if (! (flags & PEXECUTE_LAST)) - { - if (pipe (pdes) < 0) - { - *errmsg_fmt = "pipe"; - *errmsg_arg = NULL; - return -1; - } - output_desc = pdes[WRITE_PORT]; - last_pipe_input = pdes[READ_PORT]; - } - else - { - /* Last process. */ - output_desc = STDOUT_FILE_NO; - last_pipe_input = STDIN_FILE_NO; - } - - /* Fork a subprocess; wait and retry if it fails. */ - sleep_interval = 1; - pid = -1; - for (retries = 0; retries < 4; retries++) - { - pid = fork (); - if (pid >= 0) - break; - sleep (sleep_interval); - sleep_interval *= 2; - } - - switch (pid) - { - case -1: - *errmsg_fmt = "fork"; - *errmsg_arg = NULL; - return -1; - - case 0: /* child */ - /* Move the input and output pipes into place, if necessary. */ - if (input_desc != STDIN_FILE_NO) - { - close (STDIN_FILE_NO); - dup (input_desc); - close (input_desc); - } - if (output_desc != STDOUT_FILE_NO) - { - close (STDOUT_FILE_NO); - dup (output_desc); - close (output_desc); - } - - /* Close the parent's descs that aren't wanted here. */ - if (last_pipe_input != STDIN_FILE_NO) - close (last_pipe_input); - - /* Exec the program. */ - (*func) (program, argv); - - fprintf (stderr, "%s: ", this_pname); - fprintf (stderr, install_error_msg, program); - fprintf (stderr, ": %s\n", xstrerror (errno)); - _exit (-1); - /* NOTREACHED */ - return 0; - - default: - /* In the parent, after forking. - Close the descriptors that we made for this child. */ - if (input_desc != STDIN_FILE_NO) - close (input_desc); - if (output_desc != STDOUT_FILE_NO) - close (output_desc); - - /* Return child's process number. */ - return pid; - } -} - -int -pwait (pid, status, flags) - int pid; - int *status; - int flags ATTRIBUTE_UNUSED; -{ - /* ??? Here's an opportunity to canonicalize the values in STATUS. - Needed? */ -#ifdef VMS - pid = waitpid (-1, status, 0); -#else - pid = wait (status); -#endif - return pid; -} - -#endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! _UWIN) */ |