1 /* Common hooks for ATMEL AVR.
2 Copyright (C) 1998-2022 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 // With -fdelete-null-pointer-checks option, the compiler assumes
33 // that dereferencing of a null pointer would halt the program.
34 // For AVR this assumption is not true and a program can safely
35 // dereference null pointers. Changes made by this option may not
36 // work properly for AVR. So disable this option.
37 { OPT_LEVELS_ALL, OPT_fdelete_null_pointer_checks, NULL, 0 },
38 // The only effect of -fcaller-saves might be that it triggers
39 // a frame without need when it tries to be smart around calls.
40 { OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 },
41 { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_mgas_isr_prologues, NULL, 1 },
42 { OPT_LEVELS_1_PLUS, OPT_mmain_is_OS_task, NULL, 1 },
43 // Stick to the "old" placement of the subreg lowering pass.
44 { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types_early, NULL, 1 },
45 /* Allow optimizer to introduce store data races. This used to be the
46 default -- it was changed because bigger targets did not see any
47 performance decrease. For the AVR though, disallowing data races
48 introduces additional code in LIM and increases reg pressure. */
49 { OPT_LEVELS_ALL, OPT_fallow_store_data_races, NULL, 1 },
50
51 #if defined (WITH_DOUBLE64)
52 { OPT_LEVELS_ALL, OPT_mdouble_, NULL, 64 },
53 #elif defined (WITH_DOUBLE32)
54 { OPT_LEVELS_ALL, OPT_mdouble_, NULL, 32 },
55 #else
56 #error "align this with config.gcc"
57 #endif
58
59 #if defined (WITH_LONG_DOUBLE64)
60 { OPT_LEVELS_ALL, OPT_mlong_double_, NULL, 64 },
61 #elif defined (WITH_LONG_DOUBLE32)
62 { OPT_LEVELS_ALL, OPT_mlong_double_, NULL, 32 },
63 #else
64 #error "align this with config.gcc"
65 #endif
66
67 { OPT_LEVELS_NONE, 0, NULL, 0 }
68 };
69
70
71 /* Implement `TARGET_HANDLE_OPTION'. */
72
73 /* This is the same logic that driver-avr.cc:avr_double_lib() applies
74 during DRIVER_SELF_SPECS, but this time we complain about -mdouble=
75 and -mlong-double= that are not provided by --with-double= resp.
76 --with-long-double= */
77
78 static bool
avr_handle_option(struct gcc_options * opts,struct gcc_options *,const struct cl_decoded_option * decoded,location_t loc ATTRIBUTE_UNUSED)79 avr_handle_option (struct gcc_options *opts, struct gcc_options*,
80 const struct cl_decoded_option *decoded,
81 location_t loc ATTRIBUTE_UNUSED)
82 {
83 int value = decoded->value;
84
85 switch (decoded->opt_index)
86 {
87 case OPT_mdouble_:
88 if (value == 64)
89 {
90 #if !defined (HAVE_DOUBLE64)
91 error_at (loc, "option %<-mdouble=64%> is only available if "
92 "configured %<--with-double={64|64,32|32,64}%>");
93 #endif
94 opts->x_avr_long_double = 64;
95 }
96 else if (value == 32)
97 {
98 #if !defined (HAVE_DOUBLE32)
99 error_at (loc, "option %<-mdouble=32%> is only available if "
100 "configured %<--with-double={32|32,64|64,32}%>");
101 #endif
102 }
103 else
104 gcc_unreachable();
105
106 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE)
107 opts->x_avr_long_double = value;
108 #endif
109 break; // -mdouble=
110
111 case OPT_mlong_double_:
112 if (value == 64)
113 {
114 #if !defined (HAVE_LONG_DOUBLE64)
115 error_at (loc, "option %<-mlong-double=64%> is only available if "
116 "configured %<--with-long-double={64|64,32|32,64}%>, "
117 "or %<--with-long-double=double%> together with "
118 "%<--with-double={64|64,32|32,64}%>");
119 #endif
120 }
121 else if (value == 32)
122 {
123 #if !defined (HAVE_LONG_DOUBLE32)
124 error_at (loc, "option %<-mlong-double=32%> is only available if "
125 "configured %<--with-long-double={32|32,64|64,32}%>, "
126 "or %<--with-long-double=double%> together with "
127 "%<--with-double={32|32,64|64,32}%>");
128 #endif
129 opts->x_avr_double = 32;
130 }
131 else
132 gcc_unreachable();
133
134 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE)
135 opts->x_avr_double = value;
136 #endif
137 break; // -mlong-double=
138 }
139
140 return true;
141 }
142
143
144 #undef TARGET_HANDLE_OPTION
145 #define TARGET_HANDLE_OPTION avr_handle_option
146
147 #undef TARGET_OPTION_OPTIMIZATION_TABLE
148 #define TARGET_OPTION_OPTIMIZATION_TABLE avr_option_optimization_table
149
150 #undef TARGET_EXCEPT_UNWIND_INFO
151 #define TARGET_EXCEPT_UNWIND_INFO sjlj_except_unwind_info
152
153 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
154