--- gcc/config/rs6000/rs6000.c 2018/04/24 18:10:26 1.1 +++ gcc/config/rs6000/rs6000.c 2018/04/24 18:16:34 1.1.1.2 @@ -36,10 +36,16 @@ the Free Software Foundation, 675 Mass A #include "tree.h" extern char *language_string; +extern int profile_block_flag; #define min(A,B) ((A) < (B) ? (A) : (B)) #define max(A,B) ((A) > (B) ? (A) : (B)) +/* Target cpu type */ + +enum processor_type rs6000_cpu; +char *rs6000_cpu_string; + /* Set to non-zero by "fix" operation to indicate that itrunc and uitrunc must be defined. */ @@ -55,6 +61,100 @@ static int trunc_defined; rtx rs6000_compare_op0, rs6000_compare_op1; int rs6000_compare_fp_p; +/* Override command line options. Mostly we process the processor + type and sometimes adjust other TARGET_ options. */ + +void +rs6000_override_options () +{ + int i; + + /* Simplify the entries below by making a mask for any POWER + variant and any PowerPC variant. */ + +#define POWER_MASKS (MASK_POWER | MASK_POWER2) +#define POWERPC_MASKS (MASK_POWERPC | MASK_POWERPCSQR | MASK_POWERPC64) + + static struct ptt + { + char *name; /* Canonical processor name. */ + enum processor_type processor; /* Processor type enum value. */ + int target_enable; /* Target flags to enable. */ + int target_disable; /* Target flags to disable. */ + } processor_target_table[] + = {{"all", PROCESSOR_DEFAULT, 0, POWER_MASKS | POWERPC_MASKS}, + {"rios", PROCESSOR_RIOS1, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, + {"rios1", PROCESSOR_RIOS1, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, + {"rsc", PROCESSOR_PPC601, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, + {"rsc1", PROCESSOR_PPC601, MASK_POWER, MASK_POWER2 | POWERPC_MASKS}, + {"rios2", PROCESSOR_RIOS2, MASK_POWER | MASK_POWER2 , POWERPC_MASKS}, + {"601", PROCESSOR_PPC601, + MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS, + MASK_POWER2 | MASK_POWERPCSQR | MASK_POWERPC64}, + {"mpc601", PROCESSOR_PPC601, + MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS, + MASK_POWER2 | MASK_POWERPCSQR | MASK_POWERPC64}, + {"ppc601", PROCESSOR_PPC601, + MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS, + MASK_POWER2 | MASK_POWERPCSQR | MASK_POWERPC64}, + {"603", PROCESSOR_PPC603, + MASK_POWERPC | MASK_POWERPCSQR | MASK_NEW_MNEMONICS, + POWER_MASKS | MASK_POWERPC64}, + {"mpc603", PROCESSOR_PPC603, + MASK_POWERPC | MASK_POWERPCSQR | MASK_NEW_MNEMONICS, + POWER_MASKS | MASK_POWERPC64}, + {"ppc603", PROCESSOR_PPC603, + MASK_POWERPC | MASK_POWERPCSQR | MASK_NEW_MNEMONICS, + POWER_MASKS | MASK_POWERPC64}, + {"604", PROCESSOR_PPC604, + MASK_POWERPC | MASK_POWERPCSQR | MASK_NEW_MNEMONICS, + POWER_MASKS | MASK_POWERPC64}, + {"mpc604", PROCESSOR_PPC604, + MASK_POWERPC | MASK_POWERPCSQR | MASK_NEW_MNEMONICS, + POWER_MASKS | MASK_POWERPC64}, + {"ppc604", PROCESSOR_PPC604, + MASK_POWERPC | MASK_POWERPCSQR | MASK_NEW_MNEMONICS, + POWER_MASKS | MASK_POWERPC64}, + {"620", PROCESSOR_PPC620, + (MASK_POWERPC | MASK_POWERPCSQR | MASK_POWERPC64 + | MASK_NEW_MNEMONICS), + POWER_MASKS}, + {"mpc620", PROCESSOR_PPC620, + (MASK_POWERPC | MASK_POWERPCSQR | MASK_POWERPC64 + | MASK_NEW_MNEMONICS), + POWER_MASKS}, + {"ppc620", PROCESSOR_PPC620, + (MASK_POWERPC | MASK_POWERPCSQR | MASK_POWERPC64 + | MASK_NEW_MNEMONICS), + POWER_MASKS}}; + + int ptt_size = sizeof (processor_target_table) / sizeof (struct ptt); + + profile_block_flag = 0; + + /* Identify the processor type */ + if (rs6000_cpu_string == 0) + rs6000_cpu = PROCESSOR_DEFAULT; + else + { + for (i = 0; i < ptt_size; i++) + if (! strcmp (rs6000_cpu_string, processor_target_table[i].name)) + { + rs6000_cpu = processor_target_table[i].processor; + target_flags |= processor_target_table[i].target_enable; + target_flags &= ~processor_target_table[i].target_disable; + break; + } + + if (i == ptt_size) + { + error ("bad value (%s) for -mcpu= switch", rs6000_cpu_string); + rs6000_cpu_string = "default"; + rs6000_cpu = PROCESSOR_DEFAULT; + } + } +} + /* Return non-zero if this function is known to have a null epilogue. */ int @@ -144,10 +244,7 @@ reg_or_short_operand (op, mode) register rtx op; enum machine_mode mode; { - if (GET_CODE (op) == CONST_INT) - return short_cint_operand (op, mode); - - return gpc_reg_operand (op, mode); + return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); } /* Similar, except check if the negation of the constant would be valid for @@ -190,13 +287,9 @@ reg_or_cint_operand (op, mode) return GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode); } -/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a - register with one instruction per word. For SFmode, this means that - the low 16-bits are zero. For DFmode, it means the low 16-bits of - the first word are zero and the high 16 bits of the second word - are zero (usually all bits in the low-order word will be zero). - - We only do this if we can safely read CONST_DOUBLE_{LOW,HIGH}. */ +/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a register + with one instruction per word. We only do this if we can safely read + CONST_DOUBLE_{LOW,HIGH}. */ int easy_fp_constant (op, mode) @@ -213,12 +306,11 @@ easy_fp_constant (op, mode) high = operand_subword (op, 0, 0, mode); low = operand_subword (op, 1, 0, mode); - if (high == 0 || GET_CODE (high) != CONST_INT || (INTVAL (high) & 0xffff)) + if (high == 0 || ! input_operand (high, word_mode)) return 0; return (mode == SFmode - || (low != 0 && GET_CODE (low) == CONST_INT - && (INTVAL (low) & 0xffff0000) == 0)); + || (low != 0 && input_operand (low, word_mode))); } /* Return 1 if the operand is either a floating-point register, a pseudo @@ -383,6 +475,21 @@ call_operand (op, mode) || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER)); } + +/* Return 1 if the operand is a SYMBOL_REF for a function known to be in + this file. */ + +int +current_file_function_operand (op, mode) + register rtx op; + enum machine_mode mode; +{ + return (GET_CODE (op) == SYMBOL_REF + && (SYMBOL_REF_FLAG (op) + || op == XEXP (DECL_RTL (current_function_decl), 0))); +} + + /* Return 1 if this operand is a valid input for a move insn. */ int @@ -390,20 +497,27 @@ input_operand (op, mode) register rtx op; enum machine_mode mode; { + /* Memory is always valid. */ if (memory_operand (op, mode)) return 1; - /* For floating-point or multi-word mode, only register or memory - is valid. */ + /* For floating-point, easy constants are valid. */ + if (GET_MODE_CLASS (mode) == MODE_FLOAT + && CONSTANT_P (op) + && easy_fp_constant (op, mode)) + return 1; + + /* For floating-point or multi-word mode, the only remaining valid type + is a register. */ if (GET_MODE_CLASS (mode) == MODE_FLOAT || GET_MODE_SIZE (mode) > UNITS_PER_WORD) - return gpc_reg_operand (op, mode); + return register_operand (op, mode); /* The only cases left are integral modes one word or smaller (we do not get called for MODE_CC values). These can be in any register. */ if (register_operand (op, mode)) - return; + return 1; /* For HImode and QImode, any constant is valid. */ if ((mode == HImode || mode == QImode) @@ -709,15 +823,21 @@ print_operand (file, x, code) switch (code) { + case '.': + /* Write out an instruction after the call which may be replaced + with glue code by the loader. This depends on the AIX version. */ + asm_fprintf (file, RS6000_CALL_GLUE); + return; + case 'A': /* If X is a constant integer whose low-order 5 bits are zero, write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug - in the RS/6000 assembler where "sri" with a zero shift count + in the AIX assembler where "sri" with a zero shift count write a trash instruction. */ if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) - fprintf (file, "l"); + putc ('l', file); else - fprintf (file, "r"); + putc ('r', file); return; case 'b': @@ -770,7 +890,7 @@ print_operand (file, x, code) output_operand_lossage ("invalid %%E value"); fprintf(file, "%d", 4 * (REGNO (x) - 68) + 3); - break; + return; case 'f': /* X is a CR register. Print the shift count needed to move it @@ -796,9 +916,9 @@ print_operand (file, x, code) if (GET_CODE (x) != CONST_INT) output_operand_lossage ("invalid %%G value"); else if (INTVAL (x) >= 0) - fprintf (file, "z"); + putc ('z', file); else - fprintf (file, "m"); + putc ('m', file); return; case 'h': @@ -821,7 +941,7 @@ print_operand (file, x, code) case 'I': /* Print `i' if this is a constant, else nothing. */ if (INT_P (x)) - fprintf (file, "i"); + putc ('i', file); return; case 'j': @@ -840,7 +960,8 @@ print_operand (file, x, code) if (i == -1) output_operand_lossage ("invalid %%J code"); else - fprintf (file, "%d", i + 1); + /* If we want bit 31, write a shift count of zero, not 32. */ + fprintf (file, "%d", i == 31 ? 0 : i + 1); return; case 'k': @@ -916,7 +1037,7 @@ print_operand (file, x, code) the right. */ if ((val & 1) && val >= 0) { - fprintf (file, "31"); + fputs ("31", file); return; } else if ((val & 1) == 0) @@ -1011,9 +1132,9 @@ print_operand (file, x, code) || GET_CODE (x) == EQ || GET_CODE (x) == LT || GET_CODE (x) == GT || GET_CODE (x) == LTU || GET_CODE (x) == GTU) - fprintf (file, "12"); + fputs ("12", file); else - fprintf (file, "4"); + putc ('4', file); return; case 'T': @@ -1027,9 +1148,9 @@ print_operand (file, x, code) || GET_CODE (x) == EQ || GET_CODE (x) == LT || GET_CODE (x) == GT || GET_CODE (x) == LTU || GET_CODE (x) == GTU) - fprintf (file, "4"); + putc ('4', file); else - fprintf (file, "12"); + fputs ("12", file); return; case 'u': @@ -1037,7 +1158,7 @@ print_operand (file, x, code) if (! INT_P (x)) output_operand_lossage ("invalid %%u value"); - fprintf (file, "%d", (INT_LOWPART (x) >> 16) & 0xffff); + fprintf (file, "0x%x", (INT_LOWPART (x) >> 16) & 0xffff); return; case 'U': @@ -1045,7 +1166,7 @@ print_operand (file, x, code) if (GET_CODE (x) == MEM && (GET_CODE (XEXP (x, 0)) == PRE_INC || GET_CODE (XEXP (x, 0)) == PRE_DEC)) - fprintf (file, "u"); + putc ('u', file); return; case 'w': @@ -1070,7 +1191,7 @@ print_operand (file, x, code) case 'X': if (GET_CODE (x) == MEM && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0))) - fprintf (file, "x"); + putc ('x', file); return; case 'Y': @@ -1094,7 +1215,7 @@ print_operand (file, x, code) if (GET_CODE (x) != SYMBOL_REF) abort (); - fprintf (file, "."); + putc ('.', file); RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); return; @@ -1130,7 +1251,7 @@ print_operand (file, x, code) } else output_addr_const (file, x); - break; + return; default: output_operand_lossage ("invalid %%xn code"); @@ -1149,7 +1270,12 @@ print_operand_address (file, x) else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST) { output_addr_const (file, x); - fprintf (file, "(2)"); + /* When TARGET_MINIMAL_TOC, use the indirected toc table pointer instead + of the toc pointer. */ + if (TARGET_MINIMAL_TOC) + fprintf (file, "(30)"); + else + fprintf (file, "(2)"); } else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) { @@ -1222,7 +1348,6 @@ int rs6000_sa_size () { int size; - int i; /* We have the six fixed words, plus the size of the register save areas, rounded to a double-word. */ @@ -1304,52 +1429,68 @@ output_prolog (file, size) /* If we use the link register, get it into r0. */ if (regs_ever_live[65]) - fprintf (file, "\tmflr 0\n"); + asm_fprintf (file, "\tmflr 0\n"); /* If we need to save CR, put it into r12. */ if (must_save_cr ()) - fprintf (file, "\tmfcr 12\n"); + asm_fprintf (file, "\tmfcr 12\n"); /* Do any required saving of fpr's. If only one or two to save, do it - ourself. Otherwise, call function. */ + ourself. Otherwise, call function. Note that since they are statically + linked, we do not need a nop following them. */ if (first_fp_reg == 62) - fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n"); + asm_fprintf (file, "\tstfd 30,-16(1)\n\tstfd 31,-8(1)\n"); else if (first_fp_reg == 63) - fprintf (file, "\tstfd 31,-8(1)\n"); + asm_fprintf (file, "\tstfd 31,-8(1)\n"); else if (first_fp_reg != 64) - fprintf (file, "\tbl ._savef%d\n\tcror 15,15,15\n", first_fp_reg - 32); + asm_fprintf (file, "\tbl ._savef%d\n", first_fp_reg - 32); /* Now save gpr's. */ - if (first_reg == 31) - fprintf (file, "\tst 31,%d(1)\n", -4 - (64 - first_fp_reg) * 8); + if (! TARGET_POWER || first_reg == 31) + { + int regno, loc; + + for (regno = first_reg, + loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8; + regno < 32; + regno++, loc += 4) + asm_fprintf (file, "\t{st|stw} %d,%d(1)\n", regno, loc); + } + else if (first_reg != 32) - fprintf (file, "\tstm %d,%d(1)\n", first_reg, + asm_fprintf (file, "\t{stm|stmw} %d,%d(1)\n", first_reg, - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8); /* Save lr if we used it. */ if (regs_ever_live[65]) - fprintf (file, "\tst 0,8(1)\n"); + asm_fprintf (file, "\t{st|stw} 0,8(1)\n"); /* Save CR if we use any that must be preserved. */ if (must_save_cr ()) - fprintf (file, "\tst 12,4(1)\n"); + asm_fprintf (file, "\t{st|stw} 12,4(1)\n"); /* Update stack and set back pointer. */ if (must_push) { if (total_size < 32767) - fprintf (file, "\tstu 1,%d(1)\n", - total_size); + asm_fprintf (file, "\t{stu|stwu} 1,%d(1)\n", - total_size); else { - fprintf (file, "\tcau 0,0,%d\n\toril 0,0,%d\n", + asm_fprintf (file, "\t{cau|addis} 0,0,%d\n\t{oril|ori} 0,0,%d\n", (total_size >> 16) & 0xffff, total_size & 0xffff); - fprintf (file, "\tsf 12,0,1\n\tst 1,0(12)\n\toril 1,12,0\n"); + asm_fprintf (file, "\t{sf|subfc} 12,0,1\n"); + asm_fprintf (file, "\t{st|stw} 1,0(12)\n\t{oril|ori} 1,12,0\n"); } } /* Set frame pointer, if needed. */ if (frame_pointer_needed) - fprintf (file, "\toril 31,1,0\n"); + asm_fprintf (file, "\t{oril|ori} 31,1,0\n"); + + /* If TARGET_MINIMAL_TOC, and the constant pool is needed, then load the + TOC_TABLE address into register 30. */ + if (TARGET_MINIMAL_TOC && get_pool_size () != 0) + asm_fprintf (file, "\t{l|lwz} 30,LCTOC..0(2)\n"); } /* Write function epilogue. */ @@ -1380,49 +1521,58 @@ output_epilog (file, size) we know what size to update it with. */ if (frame_pointer_needed || current_function_calls_alloca || total_size > 32767) - fprintf (file, "\tl 1,0(1)\n"); + asm_fprintf (file, "\t{l|lwz} 1,0(1)\n"); else if (must_push) - fprintf (file, "\tai 1,1,%d\n", total_size); + asm_fprintf (file, "\t{ai|addic} 1,1,%d\n", total_size); /* Get the old lr if we saved it. */ if (regs_ever_live[65]) - fprintf (file, "\tl 0,8(1)\n"); + asm_fprintf (file, "\t{l|lwz} 0,8(1)\n"); /* Get the old cr if we saved it. */ if (must_save_cr ()) - fprintf (file, "\tl 12,4(1)\n"); + asm_fprintf (file, "\t{l|lwz} 12,4(1)\n"); /* Set LR here to try to overlap restores below. */ if (regs_ever_live[65]) - fprintf (file, "\tmtlr 0\n"); + asm_fprintf (file, "\tmtlr 0\n"); /* Restore gpr's. */ - if (first_reg == 31) - fprintf (file, "\tl 31,%d(1)\n", -4 - (64 - first_fp_reg) * 8); + if (! TARGET_POWER || first_reg == 31) + { + int regno, loc; + + for (regno = first_reg, + loc = - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8; + regno < 32; + regno++, loc += 4) + asm_fprintf (file, "\t{l|lwz} %d,%d(1)\n", regno, loc); + } + else if (first_reg != 32) - fprintf (file, "\tlm %d,%d(1)\n", first_reg, - - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8); + asm_fprintf (file, "\t{lm|lmw} %d,%d(1)\n", first_reg, + - (32 - first_reg) * 4 - (64 - first_fp_reg) * 8); /* Restore fpr's if we can do it without calling a function. */ if (first_fp_reg == 62) - fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n"); + asm_fprintf (file, "\tlfd 30,-16(1)\n\tlfd 31,-8(1)\n"); else if (first_fp_reg == 63) - fprintf (file, "\tlfd 31,-8(1)\n"); + asm_fprintf (file, "\tlfd 31,-8(1)\n"); /* If we saved cr, restore it here. Just those of cr2, cr3, and cr4 that were used. */ if (must_save_cr ()) - fprintf (file, "\tmtcrf %d,12\n", - (regs_ever_live[70] != 0) * 0x20 - + (regs_ever_live[71] != 0) * 0x10 - + (regs_ever_live[72] != 0) * 0x8); + asm_fprintf (file, "\tmtcrf %d,12\n", + (regs_ever_live[70] != 0) * 0x20 + + (regs_ever_live[71] != 0) * 0x10 + + (regs_ever_live[72] != 0) * 0x8); /* If we have to restore more than two FP registers, branch to the restore function. It will return to our caller. */ if (first_fp_reg < 62) - fprintf (file, "\tb ._restf%d\n\tcror 15,15,15\n", first_fp_reg - 32); + asm_fprintf (file, "\tb ._restf%d\n", first_fp_reg - 32); else - fprintf (file, "\tbr\n"); + asm_fprintf (file, "\t{br|blr}\n"); } /* Output a traceback table here. See /usr/include/sys/debug.h for info @@ -1614,27 +1764,36 @@ output_toc (file, x, labelno) ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno); - /* Handle FP constants specially. */ + /* Handle FP constants specially. Note that if we have a minimal + TOC, things we put here aren't actually in the TOC, so we can allow + FP constants. */ if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode && TARGET_FLOAT_FORMAT == HOST_FLOAT_FORMAT && BITS_PER_WORD == HOST_BITS_PER_INT - && TARGET_FP_IN_TOC) + && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { - fprintf (file, "\t.tc FD_%x_%x[TC],%d,%d\n", - CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x), - CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x)); + if (TARGET_MINIMAL_TOC) + fprintf (file, "\t.long %d\n\t.long %d\n", + CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x)); + else + fprintf (file, "\t.tc FD_%x_%x[TC],%d,%d\n", + CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x), + CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x)); return; } else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode - && TARGET_FP_IN_TOC) + && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { rtx val = operand_subword (x, 0, 0, SFmode); if (val == 0 || GET_CODE (val) != CONST_INT) abort (); - fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val)); + if (TARGET_MINIMAL_TOC) + fprintf (file, "\t.long %d\n", INTVAL (val)); + else + fprintf (file, "\t.tc FS_%x[TC],%d\n", INTVAL (val), INTVAL (val)); return; } @@ -1653,15 +1812,20 @@ output_toc (file, x, labelno) else abort (); - fprintf (file, "\t.tc "); - RS6000_OUTPUT_BASENAME (file, name); + if (TARGET_MINIMAL_TOC) + fprintf (file, "\t.long "); + else + { + fprintf (file, "\t.tc "); + RS6000_OUTPUT_BASENAME (file, name); - if (offset < 0) - fprintf (file, ".N%d", - offset); - else if (offset) - fprintf (file, ".P%d", offset); + if (offset < 0) + fprintf (file, ".N%d", - offset); + else if (offset) + fprintf (file, ".P%d", offset); - fprintf (file, "[TC],"); + fprintf (file, "[TC],"); + } output_addr_const (file, x); fprintf (file, "\n"); } @@ -1804,8 +1968,11 @@ output_function_profiler (file, labelno) /* Set up a TOC entry for the profiler label. */ toc_section (); - fprintf (file, "LPC..%d:\n\t.tc\tLP..%d[TC],LP..%d\n", - labelno, labelno, labelno); + if (TARGET_MINIMAL_TOC) + fprintf (file, "LPC..%d:\n\t.long LP..%d\n", labelno, labelno); + else + fprintf (file, "LPC..%d:\n\t.tc\tLP..%d[TC],LP..%d\n", + labelno, labelno, labelno); text_section (); /* Figure out last used parameter register. The proper thing to do is