| 1 |
/* Common hooks for AVR 8-bit microcontrollers. |
| 2 |
Copyright (C) 1998-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GCC. |
| 5 |
|
| 6 |
GCC is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
GCC is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with GCC; see the file COPYING3. If not see |
| 18 |
<http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#include "config.h" |
| 21 |
#include "system.h" |
| 22 |
#include "coretypes.h" |
| 23 |
#include "tm.h" |
| 24 |
#include "common/common-target.h" |
| 25 |
#include "common/common-target-def.h" |
| 26 |
#include "opts.h" |
| 27 |
#include "diagnostic.h" |
| 28 |
|
| 29 |
/* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */ |
| 30 |
static const struct default_options avr_option_optimization_table[] = |
| 31 |
{ |
| 32 |
// The lookup table from tree-swicth-conversion.cc lives in .rodata |
| 33 |
// and hence consumes RAM on almost all devices. As PR49857 has |
| 34 |
// been rejected several times for non-technical reasons, just |
| 35 |
// disable -ftree-switch-conversion by default. But even with PR49857 |
| 36 |
// in place there remains PR81540, which cannot be filtered out since |
| 37 |
// the pass has no way to hook in. |
| 38 |
{ OPT_LEVELS_ALL, OPT_ftree_switch_conversion, NULL, 0 }, |
| 39 |
// The only effect of -fcaller-saves might be that it triggers |
| 40 |
// a frame without need when it tries to be smart around calls. |
| 41 |
{ OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 }, |
| 42 |
// Avoid large lookup tables in RAM from -foptimize-crc. |
| 43 |
{ OPT_LEVELS_ALL, OPT_foptimize_crc, NULL, 0 }, |
| 44 |
{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_mgas_isr_prologues, NULL, 1 }, |
| 45 |
{ OPT_LEVELS_1_PLUS, OPT_mmain_is_OS_task, NULL, 1 }, |
| 46 |
{ OPT_LEVELS_1_PLUS, OPT_mfuse_add_, NULL, 1 }, |
| 47 |
{ OPT_LEVELS_2_PLUS, OPT_mfuse_add_, NULL, 2 }, |
| 48 |
{ OPT_LEVELS_1_PLUS, OPT_mfuse_move2, NULL, 1 }, |
| 49 |
{ OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_mfuse_move_, NULL, 3 }, |
| 50 |
{ OPT_LEVELS_2_PLUS, OPT_mfuse_move_, NULL, 23 }, |
| 51 |
{ OPT_LEVELS_2_PLUS, OPT_msplit_bit_shift, NULL, 1 }, |
| 52 |
{ OPT_LEVELS_2_PLUS, OPT_msplit_ldst, NULL, 1 }, |
| 53 |
{ OPT_LEVELS_2_PLUS, OPT_muse_nonzero_bits, NULL, 1 }, |
| 54 |
// Stick to the "old" placement of the subreg lowering pass. |
| 55 |
{ OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types_early, NULL, 1 }, |
| 56 |
/* Allow optimizer to introduce store data races. This used to be the |
| 57 |
default -- it was changed because bigger targets did not see any |
| 58 |
performance decrease. For the AVR though, disallowing data races |
| 59 |
introduces additional code in LIM and increases reg pressure. */ |
| 60 |
{ OPT_LEVELS_ALL, OPT_fallow_store_data_races, NULL, 1 }, |
| 61 |
|
| 62 |
#if defined (WITH_DOUBLE64) |
| 63 |
{ OPT_LEVELS_ALL, OPT_mdouble_, NULL, 64 }, |
| 64 |
#elif defined (WITH_DOUBLE32) |
| 65 |
{ OPT_LEVELS_ALL, OPT_mdouble_, NULL, 32 }, |
| 66 |
#else |
| 67 |
#error "align this with config.gcc" |
| 68 |
#endif |
| 69 |
|
| 70 |
#if defined (WITH_LONG_DOUBLE64) |
| 71 |
{ OPT_LEVELS_ALL, OPT_mlong_double_, NULL, 64 }, |
| 72 |
#elif defined (WITH_LONG_DOUBLE32) |
| 73 |
{ OPT_LEVELS_ALL, OPT_mlong_double_, NULL, 32 }, |
| 74 |
#else |
| 75 |
#error "align this with config.gcc" |
| 76 |
#endif |
| 77 |
|
| 78 |
{ OPT_LEVELS_NONE, 0, NULL, 0 } |
| 79 |
}; |
| 80 |
|
| 81 |
|
| 82 |
/* Implement `TARGET_HANDLE_OPTION'. */ |
| 83 |
|
| 84 |
/* This is the same logic that driver-avr.cc:avr_double_lib() applies |
| 85 |
during DRIVER_SELF_SPECS, but this time we complain about -mdouble= |
| 86 |
and -mlong-double= that are not provided by --with-double= resp. |
| 87 |
--with-long-double= */ |
| 88 |
|
| 89 |
static bool |
| 90 |
avr_handle_option (struct gcc_options *opts, struct gcc_options*, |
| 91 |
const struct cl_decoded_option *decoded, |
| 92 |
location_t loc ATTRIBUTE_UNUSED) |
| 93 |
{ |
| 94 |
int value = decoded->value; |
| 95 |
|
| 96 |
switch (decoded->opt_index) |
| 97 |
{ |
| 98 |
case OPT_mdouble_: |
| 99 |
if (value == 64) |
| 100 |
{ |
| 101 |
#if !defined (HAVE_DOUBLE64) |
| 102 |
error_at (loc, "option %<-mdouble=64%> is only available if " |
| 103 |
"configured %<--with-double={64|64,32|32,64}%>"); |
| 104 |
#endif |
| 105 |
opts->x_avropt_long_double = 64; |
| 106 |
} |
| 107 |
else if (value == 32) |
| 108 |
{ |
| 109 |
#if !defined (HAVE_DOUBLE32) |
| 110 |
error_at (loc, "option %<-mdouble=32%> is only available if " |
| 111 |
"configured %<--with-double={32|32,64|64,32}%>"); |
| 112 |
#endif |
| 113 |
} |
| 114 |
else |
| 115 |
gcc_unreachable(); |
| 116 |
|
| 117 |
#if defined (HAVE_LONG_DOUBLE_IS_DOUBLE) |
| 118 |
opts->x_avropt_long_double = value; |
| 119 |
#endif |
| 120 |
break; // -mdouble= |
| 121 |
|
| 122 |
case OPT_mlong_double_: |
| 123 |
if (value == 64) |
| 124 |
{ |
| 125 |
#if !defined (HAVE_LONG_DOUBLE64) |
| 126 |
error_at (loc, "option %<-mlong-double=64%> is only available if " |
| 127 |
"configured %<--with-long-double={64|64,32|32,64}%>, " |
| 128 |
"or %<--with-long-double=double%> together with " |
| 129 |
"%<--with-double={64|64,32|32,64}%>"); |
| 130 |
#endif |
| 131 |
} |
| 132 |
else if (value == 32) |
| 133 |
{ |
| 134 |
#if !defined (HAVE_LONG_DOUBLE32) |
| 135 |
error_at (loc, "option %<-mlong-double=32%> is only available if " |
| 136 |
"configured %<--with-long-double={32|32,64|64,32}%>, " |
| 137 |
"or %<--with-long-double=double%> together with " |
| 138 |
"%<--with-double={32|32,64|64,32}%>"); |
| 139 |
#endif |
| 140 |
opts->x_avropt_double = 32; |
| 141 |
} |
| 142 |
else |
| 143 |
gcc_unreachable(); |
| 144 |
|
| 145 |
#if defined (HAVE_LONG_DOUBLE_IS_DOUBLE) |
| 146 |
opts->x_avropt_double = value; |
| 147 |
#endif |
| 148 |
break; // -mlong-double= |
| 149 |
} |
| 150 |
|
| 151 |
return true; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
#undef TARGET_HANDLE_OPTION |
| 156 |
#define TARGET_HANDLE_OPTION avr_handle_option |
| 157 |
|
| 158 |
#undef TARGET_OPTION_OPTIMIZATION_TABLE |
| 159 |
#define TARGET_OPTION_OPTIMIZATION_TABLE avr_option_optimization_table |
| 160 |
|
| 161 |
#undef TARGET_EXCEPT_UNWIND_INFO |
| 162 |
#define TARGET_EXCEPT_UNWIND_INFO sjlj_except_unwind_info |
| 163 |
|
| 164 |
struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER; |