1 /* Common hooks for ATMEL AVR.
2 Copyright (C) 1998-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
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)
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.
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/>. */
22 #include "coretypes.h"
24 #include "common/common-target.h"
25 #include "common/common-target-def.h"
27 #include "diagnostic.h"
29 /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
30 static const struct default_options avr_option_optimization_table
[] =
32 // The only effect of -fcaller-saves might be that it triggers
33 // a frame without need when it tries to be smart around calls.
34 { OPT_LEVELS_ALL
, OPT_fcaller_saves
, NULL
, 0 },
35 { OPT_LEVELS_1_PLUS_NOT_DEBUG
, OPT_mgas_isr_prologues
, NULL
, 1 },
36 { OPT_LEVELS_1_PLUS
, OPT_mmain_is_OS_task
, NULL
, 1 },
37 // Stick to the "old" placement of the subreg lowering pass.
38 { OPT_LEVELS_1_PLUS
, OPT_fsplit_wide_types_early
, NULL
, 1 },
39 /* Allow optimizer to introduce store data races. This used to be the
40 default -- it was changed because bigger targets did not see any
41 performance decrease. For the AVR though, disallowing data races
42 introduces additional code in LIM and increases reg pressure. */
43 { OPT_LEVELS_ALL
, OPT_fallow_store_data_races
, NULL
, 1 },
45 #if defined (WITH_DOUBLE64)
46 { OPT_LEVELS_ALL
, OPT_mdouble_
, NULL
, 64 },
47 #elif defined (WITH_DOUBLE32)
48 { OPT_LEVELS_ALL
, OPT_mdouble_
, NULL
, 32 },
50 #error "align this with config.gcc"
53 #if defined (WITH_LONG_DOUBLE64)
54 { OPT_LEVELS_ALL
, OPT_mlong_double_
, NULL
, 64 },
55 #elif defined (WITH_LONG_DOUBLE32)
56 { OPT_LEVELS_ALL
, OPT_mlong_double_
, NULL
, 32 },
58 #error "align this with config.gcc"
61 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
65 /* Implement `TARGET_HANDLE_OPTION'. */
67 /* This is the same logic that driver-avr.cc:avr_double_lib() applies
68 during DRIVER_SELF_SPECS, but this time we complain about -mdouble=
69 and -mlong-double= that are not provided by --with-double= resp.
70 --with-long-double= */
73 avr_handle_option (struct gcc_options
*opts
, struct gcc_options
*,
74 const struct cl_decoded_option
*decoded
,
75 location_t loc ATTRIBUTE_UNUSED
)
77 int value
= decoded
->value
;
79 switch (decoded
->opt_index
)
84 #if !defined (HAVE_DOUBLE64)
85 error_at (loc
, "option %<-mdouble=64%> is only available if "
86 "configured %<--with-double={64|64,32|32,64}%>");
88 opts
->x_avr_long_double
= 64;
92 #if !defined (HAVE_DOUBLE32)
93 error_at (loc
, "option %<-mdouble=32%> is only available if "
94 "configured %<--with-double={32|32,64|64,32}%>");
100 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE)
101 opts
->x_avr_long_double
= value
;
105 case OPT_mlong_double_
:
108 #if !defined (HAVE_LONG_DOUBLE64)
109 error_at (loc
, "option %<-mlong-double=64%> is only available if "
110 "configured %<--with-long-double={64|64,32|32,64}%>, "
111 "or %<--with-long-double=double%> together with "
112 "%<--with-double={64|64,32|32,64}%>");
115 else if (value
== 32)
117 #if !defined (HAVE_LONG_DOUBLE32)
118 error_at (loc
, "option %<-mlong-double=32%> is only available if "
119 "configured %<--with-long-double={32|32,64|64,32}%>, "
120 "or %<--with-long-double=double%> together with "
121 "%<--with-double={32|32,64|64,32}%>");
123 opts
->x_avr_double
= 32;
128 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE)
129 opts
->x_avr_double
= value
;
131 break; // -mlong-double=
138 #undef TARGET_HANDLE_OPTION
139 #define TARGET_HANDLE_OPTION avr_handle_option
141 #undef TARGET_OPTION_OPTIMIZATION_TABLE
142 #define TARGET_OPTION_OPTIMIZATION_TABLE avr_option_optimization_table
144 #undef TARGET_EXCEPT_UNWIND_INFO
145 #define TARGET_EXCEPT_UNWIND_INFO sjlj_except_unwind_info
147 struct gcc_targetm_common targetm_common
= TARGETM_COMMON_INITIALIZER
;