]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/common/config/avr/avr-common.cc
7867483909dead610f43b00cd98acaa9ad922d65
[thirdparty/gcc.git] / gcc / common / config / avr / avr-common.cc
1 /* Common hooks for ATMEL AVR.
2 Copyright (C) 1998-2024 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 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 },
44
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 },
49 #else
50 #error "align this with config.gcc"
51 #endif
52
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 },
57 #else
58 #error "align this with config.gcc"
59 #endif
60
61 { OPT_LEVELS_NONE, 0, NULL, 0 }
62 };
63
64
65 /* Implement `TARGET_HANDLE_OPTION'. */
66
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= */
71
72 static bool
73 avr_handle_option (struct gcc_options *opts, struct gcc_options*,
74 const struct cl_decoded_option *decoded,
75 location_t loc ATTRIBUTE_UNUSED)
76 {
77 int value = decoded->value;
78
79 switch (decoded->opt_index)
80 {
81 case OPT_mdouble_:
82 if (value == 64)
83 {
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}%>");
87 #endif
88 opts->x_avr_long_double = 64;
89 }
90 else if (value == 32)
91 {
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}%>");
95 #endif
96 }
97 else
98 gcc_unreachable();
99
100 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE)
101 opts->x_avr_long_double = value;
102 #endif
103 break; // -mdouble=
104
105 case OPT_mlong_double_:
106 if (value == 64)
107 {
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}%>");
113 #endif
114 }
115 else if (value == 32)
116 {
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}%>");
122 #endif
123 opts->x_avr_double = 32;
124 }
125 else
126 gcc_unreachable();
127
128 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE)
129 opts->x_avr_double = value;
130 #endif
131 break; // -mlong-double=
132 }
133
134 return true;
135 }
136
137
138 #undef TARGET_HANDLE_OPTION
139 #define TARGET_HANDLE_OPTION avr_handle_option
140
141 #undef TARGET_OPTION_OPTIMIZATION_TABLE
142 #define TARGET_OPTION_OPTIMIZATION_TABLE avr_option_optimization_table
143
144 #undef TARGET_EXCEPT_UNWIND_INFO
145 #define TARGET_EXCEPT_UNWIND_INFO sjlj_except_unwind_info
146
147 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;