1 /* Common hooks for ATMEL AVR. 2 Copyright (C) 1998-2020 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.c: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 79 avr_handle_option (struct gcc_options *opts, struct gcc_options*, 80 const struct cl_decoded_option *decoded, location_t loc) 81 { 82 int value = decoded->value; 83 84 switch (decoded->opt_index) 85 { 86 case OPT_mdouble_: 87 if (value == 64) 88 { 89 #if !defined (HAVE_DOUBLE64) 90 error_at (loc, "option %<-mdouble=64%> is only available if " 91 "configured %<--with-double={64|64,32|32,64}%>"); 92 #endif 93 opts->x_avr_long_double = 64; 94 } 95 else if (value == 32) 96 { 97 #if !defined (HAVE_DOUBLE32) 98 error_at (loc, "option %<-mdouble=32%> is only available if " 99 "configured %<--with-double={32|32,64|64,32}%>"); 100 #endif 101 } 102 else 103 gcc_unreachable(); 104 105 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE) 106 opts->x_avr_long_double = value; 107 #endif 108 break; // -mdouble= 109 110 case OPT_mlong_double_: 111 if (value == 64) 112 { 113 #if !defined (HAVE_LONG_DOUBLE64) 114 error_at (loc, "option %<-mlong-double=64%> is only available if " 115 "configured %<--with-long-double={64|64,32|32,64}%>, " 116 "or %<--with-long-double=double%> together with " 117 "%<--with-double={64|64,32|32,64}%>"); 118 #endif 119 } 120 else if (value == 32) 121 { 122 #if !defined (HAVE_LONG_DOUBLE32) 123 error_at (loc, "option %<-mlong-double=32%> is only available if " 124 "configured %<--with-long-double={32|32,64|64,32}%>, " 125 "or %<--with-long-double=double%> together with " 126 "%<--with-double={32|32,64|64,32}%>"); 127 #endif 128 opts->x_avr_double = 32; 129 } 130 else 131 gcc_unreachable(); 132 133 #if defined (HAVE_LONG_DOUBLE_IS_DOUBLE) 134 opts->x_avr_double = value; 135 #endif 136 break; // -mlong-double= 137 } 138 139 return true; 140 } 141 142 143 #undef TARGET_HANDLE_OPTION 144 #define TARGET_HANDLE_OPTION avr_handle_option 145 146 #undef TARGET_OPTION_OPTIMIZATION_TABLE 147 #define TARGET_OPTION_OPTIMIZATION_TABLE avr_option_optimization_table 148 149 #undef TARGET_EXCEPT_UNWIND_INFO 150 #define TARGET_EXCEPT_UNWIND_INFO sjlj_except_unwind_info 151 152 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER; 153