--- gcc/config/alpha/alpha.c 2018/04/24 18:22:29 1.1.1.3 +++ gcc/config/alpha/alpha.c 2018/04/24 18:30:10 1.1.1.4 @@ -1,5 +1,5 @@ /* Subroutines used for code generation on the DEC Alpha. - Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) This file is part of GNU CC. @@ -16,7 +16,8 @@ GNU General Public License for more deta You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ #include @@ -58,6 +59,7 @@ static int inside_function = FALSE; int alpha_function_needs_gp; extern char *version_string; +extern int rtx_equal_function_value_matters; /* Declarations of static functions. */ static void alpha_set_memflags_1 PROTO((rtx, int, int, int)); @@ -135,10 +137,9 @@ add_operand (op, mode) enum machine_mode mode; { if (GET_CODE (op) == CONST_INT) - return ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) < 0x10000 - || ((INTVAL (op) & 0xffff) == 0 - && (INTVAL (op) >> 31 == -1 - || INTVAL (op) >> 31 == 0))); + return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K') + || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L') + || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O')); return register_operand (op, mode); } @@ -322,7 +323,8 @@ input_operand (op, mode) case LABEL_REF: case SYMBOL_REF: case CONST: - return mode == DImode; + /* This handles both the Windows/NT and OSF cases. */ + return mode == ptr_mode || mode == DImode; case REG: return 1; @@ -353,6 +355,7 @@ current_file_function_operand (op, mode) enum machine_mode mode; { return (GET_CODE (op) == SYMBOL_REF + && ! profile_flag && ! profile_block_flag && (SYMBOL_REF_FLAG (op) || op == XEXP (DECL_RTL (current_function_decl), 0))); } @@ -367,8 +370,7 @@ call_operand (op, mode) if (mode != Pmode) return 0; - return (GET_CODE (op) == SYMBOL_REF - || (GET_CODE (op) == REG && REGNO (op) == 27)); + return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG); } /* Return 1 if OP is a valid Alpha comparison operator. Here we know which @@ -655,34 +657,43 @@ alpha_set_memflags (insn, ref) } /* Try to output insns to set TARGET equal to the constant C if it can be - done in less than N insns. Returns 1 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. */ + 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. */ -int -alpha_emit_set_const (target, c, n) +rtx +alpha_emit_set_const (target, mode, c, n) rtx target; + enum machine_mode mode; HOST_WIDE_INT c; int n; { HOST_WIDE_INT new = c; int i, bits; + /* Use a pseudo if highly optimizing and still generating RTL. */ + rtx subtarget + = (flag_expensive_optimizations && rtx_equal_function_value_matters + ? 0 : target); + rtx temp; #if HOST_BITS_PER_WIDE_INT == 64 /* We are only called for SImode and DImode. If this is SImode, ensure that we are sign extended to a full word. This does not make any sense when cross-compiling on a narrow machine. */ - if (GET_MODE (target) == SImode) + if (mode == SImode) c = (c & 0xffffffff) - 2 * (c & 0x80000000); #endif /* 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. */ + a sign-extended 32-bit constant when compiling on a narrow machine. + Note that we cannot handle the constant 0x80000000. */ - if (HOST_BITS_PER_WIDE_INT != 64 - || c >> 31 == -1 || c >> 31 == 0) + if ((HOST_BITS_PER_WIDE_INT != 64 + || c >> 31 == -1 || c >> 31 == 0) + && c != 0x80000000U) { HOST_WIDE_INT low = (c & 0xffff) - 2 * (c & 0x8000); HOST_WIDE_INT tmp1 = c - low; @@ -701,30 +712,35 @@ alpha_emit_set_const (target, c, n) } if (c == low || (low == 0 && extra == 0)) + return copy_to_suggested_reg (GEN_INT (c), target, mode); + else if (n >= 2 + (extra != 0) + /* We can't do this when SImode if HIGH required adjustment. + This is because the code relies on an implicit overflow + which is invisible to the RTL. We can thus get incorrect + code if the two ldah instructions are combined. */ + && ! (mode == SImode && extra != 0)) { - emit_move_insn (target, GEN_INT (c)); - return 1; - } - else if (n >= 2 + (extra != 0)) - { - emit_move_insn (target, GEN_INT (low)); + temp = copy_to_suggested_reg (GEN_INT (low), subtarget, mode); + if (extra != 0) - emit_insn (gen_add2_insn (target, GEN_INT (extra << 16))); + temp = expand_binop (mode, add_optab, temp, GEN_INT (extra << 16), + subtarget, 0, OPTAB_WIDEN); - emit_insn (gen_add2_insn (target, GEN_INT (high << 16))); - return 1; + return expand_binop (mode, add_optab, temp, GEN_INT (high << 16), + target, 0, OPTAB_WIDEN); } } - /* If we couldn't do it that way, try some other methods (that depend on - being able to compute in the target's word size). But if we have no - instructions left, don't bother. Also, don't even try if this is - SImode (in which case we should have already done something, but - do a sanity check here). */ + /* 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 || HOST_BITS_PER_WIDE_INT < 64 || GET_MODE (target) != DImode) + if (n == 1 + || (mode == SImode && ! rtx_equal_function_value_matters)) return 0; +#if HOST_BITS_PER_WIDE_INT == 64 /* First, 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. */ @@ -733,26 +749,29 @@ alpha_emit_set_const (target, c, n) if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0) new |= (HOST_WIDE_INT) 0xff << i; - if (alpha_emit_set_const (target, new, n - 1)) - { - emit_insn (gen_anddi3 (target, target, GEN_INT (c | ~ new))); - return 1; - } + /* 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) - 2 * (new & 0x80000000); + + if (new != c + && (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 - /* Find, see if we can load a related constant and then shift and possibly + /* 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 try complementing. */ - if (alpha_emit_set_const (target, ~ c, i)) - { - emit_insn (gen_one_cmpldi2 (target, target)); - return 1; - } + if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0) + return expand_unop (mode, one_cmpl_optab, temp, target, 0); - /* First try to form a constant and do a left shift. We can do this + /* 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 @@ -763,44 +782,49 @@ alpha_emit_set_const (target, c, n) if ((bits = exact_log2 (c & - c)) > 0) for (; bits > 0; bits--) - if (alpha_emit_set_const (target, c >> bits, i) - || alpha_emit_set_const (target, - ((unsigned HOST_WIDE_INT) c) >> bits, - i)) - { - emit_insn (gen_ashldi3 (target, target, GEN_INT (bits))); - return 1; - } + if ((temp = (alpha_emit_set_const + (subtarget, mode, + (unsigned HOST_WIDE_INT) 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. */ + all zero and all ones. Be careful to avoid shifting outside the + mode and to avoid shifting outside the host wide int size. */ - if ((bits = HOST_BITS_PER_WIDE_INT - floor_log2 (c) - 1) > 0) + if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8) + - floor_log2 (c) - 1)) > 0) for (; bits > 0; bits--) - if (alpha_emit_set_const (target, c << bits, i) - || alpha_emit_set_const (target, - ((c << bits) - | (((HOST_WIDE_INT) 1 << bits) - 1)), - i)) - { - emit_insn (gen_lshrdi3 (target, target, GEN_INT (bits))); - return 1; - } + 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. */ + 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 = HOST_BITS_PER_WIDE_INT - floor_log2 (~ c) - 2) > 0) + if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8) + - floor_log2 (~ c) - 2)) > 0) for (; bits > 0; bits--) - if (alpha_emit_set_const (target, c << bits, i) - || alpha_emit_set_const (target, - ((c << bits) - | (((HOST_WIDE_INT) 1 << bits) - 1)), - i)) - { - emit_insn (gen_ashrdi3 (target, target, GEN_INT (bits))); - return 1; - } + 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); } return 0; @@ -1053,6 +1077,23 @@ print_operand (file, x, code) fprintf (file, "%s", GET_RTX_NAME (reverse_condition (GET_CODE (x)))); break; + case 'c': + /* Similar to `c', but swap. We can't get unsigned here either. */ + if (GET_RTX_CLASS (GET_CODE (x)) != '<') + output_operand_lossage ("invalid %%D value"); + + fprintf (file, "%s", GET_RTX_NAME (swap_condition (GET_CODE (x)))); + break; + + case 'd': + /* Similar, but reverse and swap. We can't get unsigned here either. */ + if (GET_RTX_CLASS (GET_CODE (x)) != '<') + output_operand_lossage ("invalid %%D value"); + + fprintf (file, "%s", + GET_RTX_NAME (swap_condition (reverse_condition ((GET_CODE (x)))))); + break; + case 'E': /* Write the divide or modulus operator. */ switch (GET_CODE (x)) @@ -1125,25 +1166,30 @@ alpha_builtin_saveregs (arglist) order to account for the integer arg registers which are counted in argsize above, but which are not actually stored on the stack. */ - addr = (current_function_args_info <= 6 + addr = (current_function_args_info <= 5 + stdarg ? plus_constant (virtual_incoming_args_rtx, 6 * UNITS_PER_WORD) : plus_constant (virtual_incoming_args_rtx, - (6 * UNITS_PER_WORD))); + addr = force_operand (addr, NULL_RTX); + /* Allocate the va_list constructor */ block = assign_stack_local (BLKmode, 2 * UNITS_PER_WORD, BITS_PER_WORD); RTX_UNCHANGING_P (block) = 1; RTX_UNCHANGING_P (XEXP (block, 0)) = 1; - /* Store the address of the first integer register in the - __va_base member. */ - emit_move_insn (change_address (block, Pmode, XEXP (block, 0)), - force_operand (addr, NULL_RTX)); + /* Store the address of the first integer register in the __base member. */ + +#ifdef POINTERS_EXTEND_UNSIGNED + addr = convert_memory_address (ptr_mode, addr); +#endif + + emit_move_insn (change_address (block, ptr_mode, XEXP (block, 0)), addr); /* Store the argsize as the __va_offset member. */ - emit_move_insn (change_address (block, Pmode, + emit_move_insn (change_address (block, TYPE_MODE (integer_type_node), plus_constant (XEXP (block, 0), - UNITS_PER_WORD)), - force_operand (argsize, NULL_RTX)); + POINTER_SIZE/BITS_PER_UNIT)), + argsize); /* Return the address of the va_list constructor, but don't put it in a register. Doing so would fail when not optimizing and produce worse @@ -1185,13 +1231,14 @@ direct_return () { return (reload_completed && alpha_sa_size () == 0 && get_frame_size () == 0 + && current_function_outgoing_args_size == 0 && current_function_pretend_args_size == 0); } /* Write a version stamp. Don't write anything if we are running as a cross-compiler. Otherwise, use the versions in /usr/include/stamp.h. */ -#ifndef CROSS_COMPILE +#if !defined(CROSS_COMPILE) && !defined(_WIN32) #include #endif @@ -1294,7 +1341,7 @@ output_prolog (file, size) 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 accesible. */ + like to put out last_linenum from final.c, but it is not accessible. */ if (write_symbols == SDB_DEBUG) { @@ -1322,7 +1369,9 @@ output_prolog (file, size) /* 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. */ + our address is taken and passed to something like qsort. + + We never need a GP for Windows/NT. */ alpha_function_needs_gp = 0; for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) @@ -1337,12 +1386,15 @@ output_prolog (file, size) break; } - if (alpha_function_needs_gp) - fprintf (file, "\tldgp $29,0($27)\n"); + if (WINDOWS_NT == 0) + { + if (alpha_function_needs_gp) + fprintf (file, "\tldgp $29,0($27)\n"); - /* Put a label after the GP load so we can enter the function at it. */ - assemble_name (file, alpha_function_name); - fprintf (file, "..ng:\n"); + /* Put a label after the GP load so we can enter the function at it. */ + assemble_name (file, alpha_function_name); + fprintf (file, "..ng:\n"); + } /* 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 @@ -1358,19 +1410,15 @@ output_prolog (file, size) if (frame_size > 4096) { int probed = 4096; - int regnum = 2; /* $1 is static chain, so start with $2. */ - fprintf (file, "\tldq $%d,-%d($30)\n", regnum++, probed); + fprintf (file, "\tstq $31,-%d($30)\n", probed); while (probed + 8192 < frame_size) - fprintf (file, "\tldq $%d,-%d($30)\n", regnum++, probed += 8192); + fprintf (file, "\tstq $31,-%d($30)\n", probed += 8192); /* We only have to do this probe if we aren't saving registers. */ if (sa_size == 0 && probed + 4096 < frame_size) - fprintf (file, "\tldq $%d,-%d($30)\n", regnum++, probed += 4096); - - if (regnum > 9) - abort (); + fprintf (file, "\tstq $31,-%d($30)\n", frame_size); } if (frame_size != 0) @@ -1394,7 +1442,7 @@ output_prolog (file, size) assemble_name (file, alpha_function_name); fprintf (file, "..sc:\n"); - fprintf (file, "\tldq $6,-8192($4)\n"); + fprintf (file, "\tstq $31,-8192($4)\n"); fprintf (file, "\tsubq $5,1,$5\n"); fprintf (file, "\tlda $4,-8192($4)\n"); @@ -1402,10 +1450,10 @@ output_prolog (file, size) assemble_name (file, alpha_function_name); fprintf (file, "..sc\n"); - fprintf (file, "\tlda $30,-%d($4)\n", leftover); - if (leftover > 4096 && sa_size == 0) - fprintf (file, "\tldq $2,%d($30)\n", leftover - 4096); + fprintf (file, "\tstq $31,-%d($4)\n", leftover); + + fprintf (file, "\tlda $30,-%d($4)\n", leftover); } /* Describe our frame. */ @@ -1490,7 +1538,7 @@ output_epilog (file, size) insn = prev_nonnote_insn (insn); if (insn == 0 || GET_CODE (insn) != BARRIER) { - int fp_offset; + int fp_offset = 0; /* If we have a frame pointer, restore SP from it. */ if (frame_pointer_needed) @@ -1537,7 +1585,7 @@ output_epilog (file, size) /* If we needed a frame pointer and we have to restore it, do it now. This must be done in one instruction immediately before the SP update. */ - if (restore_fp) + if (restore_fp && fp_offset) fprintf (file, "\tldq $15,%d($30)\n", fp_offset); /* Now update the stack pointer, if needed. Only one instruction must @@ -1559,6 +1607,9 @@ output_epilog (file, size) assemble_name (file, alpha_function_name); fprintf (file, "\n"); inside_function = FALSE; + + /* Show that we know this function if it is called again. */ + SYMBOL_REF_FLAG (XEXP (DECL_RTL (current_function_decl), 0)) = 1; } /* Debugging support. */