Home | History | Annotate | Line # | Download | only in i386
i386-options.cc revision 1.1
      1 /* Copyright (C) 1988-2022 Free Software Foundation, Inc.
      2 
      3 This file is part of GCC.
      4 
      5 GCC is free software; you can redistribute it and/or modify
      6 it under the terms of the GNU General Public License as published by
      7 the Free Software Foundation; either version 3, or (at your option)
      8 any later version.
      9 
     10 GCC is distributed in the hope that it will be useful,
     11 but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 GNU General Public License for more details.
     14 
     15 You should have received a copy of the GNU General Public License
     16 along with GCC; see the file COPYING3.  If not see
     17 <http://www.gnu.org/licenses/>.  */
     18 
     19 #define IN_TARGET_CODE 1
     20 
     21 #include "config.h"
     22 #include "system.h"
     23 #include "coretypes.h"
     24 #include "backend.h"
     25 #include "rtl.h"
     26 #include "tree.h"
     27 #include "memmodel.h"
     28 #include "gimple.h"
     29 #include "cfghooks.h"
     30 #include "cfgloop.h"
     31 #include "df.h"
     32 #include "tm_p.h"
     33 #include "stringpool.h"
     34 #include "expmed.h"
     35 #include "optabs.h"
     36 #include "regs.h"
     37 #include "emit-rtl.h"
     38 #include "recog.h"
     39 #include "cgraph.h"
     40 #include "diagnostic.h"
     41 #include "cfgbuild.h"
     42 #include "alias.h"
     43 #include "fold-const.h"
     44 #include "attribs.h"
     45 #include "calls.h"
     46 #include "stor-layout.h"
     47 #include "varasm.h"
     48 #include "output.h"
     49 #include "insn-attr.h"
     50 #include "flags.h"
     51 #include "except.h"
     52 #include "explow.h"
     53 #include "expr.h"
     54 #include "cfgrtl.h"
     55 #include "common/common-target.h"
     56 #include "langhooks.h"
     57 #include "reload.h"
     58 #include "gimplify.h"
     59 #include "dwarf2.h"
     60 #include "tm-constrs.h"
     61 #include "cselib.h"
     62 #include "sched-int.h"
     63 #include "opts.h"
     64 #include "tree-pass.h"
     65 #include "context.h"
     66 #include "pass_manager.h"
     67 #include "target-globals.h"
     68 #include "gimple-iterator.h"
     69 #include "tree-vectorizer.h"
     70 #include "shrink-wrap.h"
     71 #include "builtins.h"
     72 #include "rtl-iter.h"
     73 #include "tree-iterator.h"
     74 #include "dbgcnt.h"
     75 #include "case-cfn-macros.h"
     76 #include "dojump.h"
     77 #include "fold-const-call.h"
     78 #include "tree-vrp.h"
     79 #include "tree-ssanames.h"
     80 #include "selftest.h"
     81 #include "selftest-rtl.h"
     82 #include "print-rtl.h"
     83 #include "intl.h"
     84 #include "ifcvt.h"
     85 #include "symbol-summary.h"
     86 #include "ipa-prop.h"
     87 #include "ipa-fnsummary.h"
     88 #include "wide-int-bitmask.h"
     89 #include "tree-vector-builder.h"
     90 #include "debug.h"
     91 #include "dwarf2out.h"
     92 #include "i386-options.h"
     93 
     94 #include "x86-tune-costs.h"
     95 
     96 #ifndef SUBTARGET32_DEFAULT_CPU
     97 #define SUBTARGET32_DEFAULT_CPU "i386"
     98 #endif
     99 
    100 /* Processor feature/optimization bitmasks.  */
    101 #define m_NONE HOST_WIDE_INT_0U
    102 #define m_ALL (~HOST_WIDE_INT_0U)
    103 #define m_386 (HOST_WIDE_INT_1U<<PROCESSOR_I386)
    104 #define m_486 (HOST_WIDE_INT_1U<<PROCESSOR_I486)
    105 #define m_PENT (HOST_WIDE_INT_1U<<PROCESSOR_PENTIUM)
    106 #define m_LAKEMONT (HOST_WIDE_INT_1U<<PROCESSOR_LAKEMONT)
    107 #define m_PPRO (HOST_WIDE_INT_1U<<PROCESSOR_PENTIUMPRO)
    108 #define m_PENT4 (HOST_WIDE_INT_1U<<PROCESSOR_PENTIUM4)
    109 #define m_NOCONA (HOST_WIDE_INT_1U<<PROCESSOR_NOCONA)
    110 #define m_P4_NOCONA (m_PENT4 | m_NOCONA)
    111 #define m_CORE2 (HOST_WIDE_INT_1U<<PROCESSOR_CORE2)
    112 #define m_NEHALEM (HOST_WIDE_INT_1U<<PROCESSOR_NEHALEM)
    113 #define m_SANDYBRIDGE (HOST_WIDE_INT_1U<<PROCESSOR_SANDYBRIDGE)
    114 #define m_HASWELL (HOST_WIDE_INT_1U<<PROCESSOR_HASWELL)
    115 #define m_BONNELL (HOST_WIDE_INT_1U<<PROCESSOR_BONNELL)
    116 #define m_SILVERMONT (HOST_WIDE_INT_1U<<PROCESSOR_SILVERMONT)
    117 #define m_KNL (HOST_WIDE_INT_1U<<PROCESSOR_KNL)
    118 #define m_KNM (HOST_WIDE_INT_1U<<PROCESSOR_KNM)
    119 #define m_SKYLAKE (HOST_WIDE_INT_1U<<PROCESSOR_SKYLAKE)
    120 #define m_SKYLAKE_AVX512 (HOST_WIDE_INT_1U<<PROCESSOR_SKYLAKE_AVX512)
    121 #define m_CANNONLAKE (HOST_WIDE_INT_1U<<PROCESSOR_CANNONLAKE)
    122 #define m_ICELAKE_CLIENT (HOST_WIDE_INT_1U<<PROCESSOR_ICELAKE_CLIENT)
    123 #define m_ICELAKE_SERVER (HOST_WIDE_INT_1U<<PROCESSOR_ICELAKE_SERVER)
    124 #define m_CASCADELAKE (HOST_WIDE_INT_1U<<PROCESSOR_CASCADELAKE)
    125 #define m_TIGERLAKE (HOST_WIDE_INT_1U<<PROCESSOR_TIGERLAKE)
    126 #define m_COOPERLAKE (HOST_WIDE_INT_1U<<PROCESSOR_COOPERLAKE)
    127 #define m_SAPPHIRERAPIDS (HOST_WIDE_INT_1U<<PROCESSOR_SAPPHIRERAPIDS)
    128 #define m_ALDERLAKE (HOST_WIDE_INT_1U<<PROCESSOR_ALDERLAKE)
    129 #define m_ROCKETLAKE (HOST_WIDE_INT_1U<<PROCESSOR_ROCKETLAKE)
    130 #define m_CORE_AVX512 (m_SKYLAKE_AVX512 | m_CANNONLAKE \
    131 		       | m_ICELAKE_CLIENT | m_ICELAKE_SERVER | m_CASCADELAKE \
    132 		       | m_TIGERLAKE | m_COOPERLAKE | m_SAPPHIRERAPIDS \
    133 		       | m_ROCKETLAKE)
    134 #define m_CORE_AVX2 (m_HASWELL | m_SKYLAKE | m_CORE_AVX512)
    135 #define m_CORE_ALL (m_CORE2 | m_NEHALEM  | m_SANDYBRIDGE | m_CORE_AVX2)
    136 #define m_GOLDMONT (HOST_WIDE_INT_1U<<PROCESSOR_GOLDMONT)
    137 #define m_GOLDMONT_PLUS (HOST_WIDE_INT_1U<<PROCESSOR_GOLDMONT_PLUS)
    138 #define m_TREMONT (HOST_WIDE_INT_1U<<PROCESSOR_TREMONT)
    139 #define m_INTEL (HOST_WIDE_INT_1U<<PROCESSOR_INTEL)
    140 /* Gather Data Sampling / CVE-2022-40982 / INTEL-SA-00828.
    141    Software mitigation.  */
    142 #define m_GDS (m_SKYLAKE | m_SKYLAKE_AVX512 | m_CANNONLAKE \
    143 	       | m_ICELAKE_CLIENT | m_ICELAKE_SERVER | m_CASCADELAKE \
    144 	       | m_TIGERLAKE | m_COOPERLAKE | m_ROCKETLAKE)
    145 
    146 #define m_GEODE (HOST_WIDE_INT_1U<<PROCESSOR_GEODE)
    147 #define m_K6 (HOST_WIDE_INT_1U<<PROCESSOR_K6)
    148 #define m_K6_GEODE (m_K6 | m_GEODE)
    149 #define m_K8 (HOST_WIDE_INT_1U<<PROCESSOR_K8)
    150 #define m_ATHLON (HOST_WIDE_INT_1U<<PROCESSOR_ATHLON)
    151 #define m_ATHLON_K8 (m_K8 | m_ATHLON)
    152 #define m_AMDFAM10 (HOST_WIDE_INT_1U<<PROCESSOR_AMDFAM10)
    153 #define m_BDVER1 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER1)
    154 #define m_BDVER2 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER2)
    155 #define m_BDVER3 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER3)
    156 #define m_BDVER4 (HOST_WIDE_INT_1U<<PROCESSOR_BDVER4)
    157 #define m_ZNVER1 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER1)
    158 #define m_ZNVER2 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER2)
    159 #define m_ZNVER3 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER3)
    160 #define m_ZNVER4 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER4)
    161 #define m_ZNVER5 (HOST_WIDE_INT_1U<<PROCESSOR_ZNVER5)
    162 #define m_BTVER1 (HOST_WIDE_INT_1U<<PROCESSOR_BTVER1)
    163 #define m_BTVER2 (HOST_WIDE_INT_1U<<PROCESSOR_BTVER2)
    164 #define m_BDVER	(m_BDVER1 | m_BDVER2 | m_BDVER3 | m_BDVER4)
    165 #define m_BTVER (m_BTVER1 | m_BTVER2)
    166 #define m_ZNVER (m_ZNVER1 | m_ZNVER2 | m_ZNVER3 | m_ZNVER4 | m_ZNVER5)
    167 #define m_AMD_MULTIPLE (m_ATHLON_K8 | m_AMDFAM10 | m_BDVER | m_BTVER \
    168 			| m_ZNVER)
    169 
    170 #define m_GENERIC (HOST_WIDE_INT_1U<<PROCESSOR_GENERIC)
    171 
    172 const char* ix86_tune_feature_names[X86_TUNE_LAST] = {
    173 #undef DEF_TUNE
    174 #define DEF_TUNE(tune, name, selector) name,
    175 #include "x86-tune.def"
    176 #undef DEF_TUNE
    177 };
    178 
    179 /* Feature tests against the various tunings.  */
    180 unsigned char ix86_tune_features[X86_TUNE_LAST];
    181 
    182 /* Feature tests against the various tunings used to create ix86_tune_features
    183    based on the processor mask.  */
    184 static unsigned HOST_WIDE_INT initial_ix86_tune_features[X86_TUNE_LAST] = {
    185 #undef DEF_TUNE
    186 #define DEF_TUNE(tune, name, selector) selector,
    187 #include "x86-tune.def"
    188 #undef DEF_TUNE
    189 };
    190 
    191 /* Feature tests against the various architecture variations.  */
    192 unsigned char ix86_arch_features[X86_ARCH_LAST];
    193 
    194 struct ix86_target_opts
    195 {
    196   const char *option;		/* option string */
    197   HOST_WIDE_INT mask;		/* isa mask options */
    198 };
    199 
    200 /* This table is ordered so that options like -msse4.2 that imply other
    201    ISAs come first.  Target string will be displayed in the same order.  */
    202 static struct ix86_target_opts isa2_opts[] =
    203 {
    204   { "-mcx16",		OPTION_MASK_ISA2_CX16 },
    205   { "-mvaes",		OPTION_MASK_ISA2_VAES },
    206   { "-mrdpid",		OPTION_MASK_ISA2_RDPID },
    207   { "-mpconfig",	OPTION_MASK_ISA2_PCONFIG },
    208   { "-mwbnoinvd",	OPTION_MASK_ISA2_WBNOINVD },
    209   { "-mavx512vp2intersect", OPTION_MASK_ISA2_AVX512VP2INTERSECT },
    210   { "-msgx",		OPTION_MASK_ISA2_SGX },
    211   { "-mavx5124vnniw",	OPTION_MASK_ISA2_AVX5124VNNIW },
    212   { "-mavx5124fmaps",	OPTION_MASK_ISA2_AVX5124FMAPS },
    213   { "-mhle",		OPTION_MASK_ISA2_HLE },
    214   { "-mmovbe",		OPTION_MASK_ISA2_MOVBE },
    215   { "-mclzero",		OPTION_MASK_ISA2_CLZERO },
    216   { "-mmwaitx",		OPTION_MASK_ISA2_MWAITX },
    217   { "-mmwait",		OPTION_MASK_ISA2_MWAIT },
    218   { "-mmovdir64b",	OPTION_MASK_ISA2_MOVDIR64B },
    219   { "-mwaitpkg",	OPTION_MASK_ISA2_WAITPKG },
    220   { "-mcldemote",	OPTION_MASK_ISA2_CLDEMOTE },
    221   { "-mptwrite",	OPTION_MASK_ISA2_PTWRITE },
    222   { "-mavx512bf16",	OPTION_MASK_ISA2_AVX512BF16 },
    223   { "-menqcmd",		OPTION_MASK_ISA2_ENQCMD },
    224   { "-mserialize",	OPTION_MASK_ISA2_SERIALIZE },
    225   { "-mtsxldtrk",	OPTION_MASK_ISA2_TSXLDTRK },
    226   { "-mamx-tile",	OPTION_MASK_ISA2_AMX_TILE },
    227   { "-mamx-int8",	OPTION_MASK_ISA2_AMX_INT8 },
    228   { "-mamx-bf16",	OPTION_MASK_ISA2_AMX_BF16 },
    229   { "-muintr",		OPTION_MASK_ISA2_UINTR },
    230   { "-mhreset",		OPTION_MASK_ISA2_HRESET },
    231   { "-mkl",		OPTION_MASK_ISA2_KL },
    232   { "-mwidekl", 	OPTION_MASK_ISA2_WIDEKL },
    233   { "-mavxvnni",	OPTION_MASK_ISA2_AVXVNNI },
    234   { "-mavx512fp16",	OPTION_MASK_ISA2_AVX512FP16 }
    235 };
    236 static struct ix86_target_opts isa_opts[] =
    237 {
    238   { "-mavx512vpopcntdq", OPTION_MASK_ISA_AVX512VPOPCNTDQ },
    239   { "-mavx512bitalg",	OPTION_MASK_ISA_AVX512BITALG },
    240   { "-mvpclmulqdq",	OPTION_MASK_ISA_VPCLMULQDQ },
    241   { "-mgfni",		OPTION_MASK_ISA_GFNI },
    242   { "-mavx512vnni",	OPTION_MASK_ISA_AVX512VNNI },
    243   { "-mavx512vbmi2",	OPTION_MASK_ISA_AVX512VBMI2 },
    244   { "-mavx512vbmi",	OPTION_MASK_ISA_AVX512VBMI },
    245   { "-mavx512ifma",	OPTION_MASK_ISA_AVX512IFMA },
    246   { "-mavx512vl",	OPTION_MASK_ISA_AVX512VL },
    247   { "-mavx512bw",	OPTION_MASK_ISA_AVX512BW },
    248   { "-mavx512dq",	OPTION_MASK_ISA_AVX512DQ },
    249   { "-mavx512er",	OPTION_MASK_ISA_AVX512ER },
    250   { "-mavx512pf",	OPTION_MASK_ISA_AVX512PF },
    251   { "-mavx512cd",	OPTION_MASK_ISA_AVX512CD },
    252   { "-mavx512f",	OPTION_MASK_ISA_AVX512F },
    253   { "-mavx2",		OPTION_MASK_ISA_AVX2 },
    254   { "-mfma",		OPTION_MASK_ISA_FMA },
    255   { "-mxop",		OPTION_MASK_ISA_XOP },
    256   { "-mfma4",		OPTION_MASK_ISA_FMA4 },
    257   { "-mf16c",		OPTION_MASK_ISA_F16C },
    258   { "-mavx",		OPTION_MASK_ISA_AVX },
    259 /*{ "-msse4"		OPTION_MASK_ISA_SSE4 }, */
    260   { "-msse4.2",		OPTION_MASK_ISA_SSE4_2 },
    261   { "-msse4.1",		OPTION_MASK_ISA_SSE4_1 },
    262   { "-msse4a",		OPTION_MASK_ISA_SSE4A },
    263   { "-mssse3",		OPTION_MASK_ISA_SSSE3 },
    264   { "-msse3",		OPTION_MASK_ISA_SSE3 },
    265   { "-maes",		OPTION_MASK_ISA_AES },
    266   { "-msha",		OPTION_MASK_ISA_SHA },
    267   { "-mpclmul",		OPTION_MASK_ISA_PCLMUL },
    268   { "-msse2",		OPTION_MASK_ISA_SSE2 },
    269   { "-msse",		OPTION_MASK_ISA_SSE },
    270   { "-m3dnowa",		OPTION_MASK_ISA_3DNOW_A },
    271   { "-m3dnow",		OPTION_MASK_ISA_3DNOW },
    272   { "-mmmx",		OPTION_MASK_ISA_MMX },
    273   { "-mrtm",		OPTION_MASK_ISA_RTM },
    274   { "-mprfchw",		OPTION_MASK_ISA_PRFCHW },
    275   { "-mrdseed",		OPTION_MASK_ISA_RDSEED },
    276   { "-madx",		OPTION_MASK_ISA_ADX },
    277   { "-mprefetchwt1",	OPTION_MASK_ISA_PREFETCHWT1 },
    278   { "-mclflushopt",	OPTION_MASK_ISA_CLFLUSHOPT },
    279   { "-mxsaves",		OPTION_MASK_ISA_XSAVES },
    280   { "-mxsavec",		OPTION_MASK_ISA_XSAVEC },
    281   { "-mxsaveopt",	OPTION_MASK_ISA_XSAVEOPT },
    282   { "-mxsave",		OPTION_MASK_ISA_XSAVE },
    283   { "-mabm",		OPTION_MASK_ISA_ABM },
    284   { "-mbmi",		OPTION_MASK_ISA_BMI },
    285   { "-mbmi2",		OPTION_MASK_ISA_BMI2 },
    286   { "-mlzcnt",		OPTION_MASK_ISA_LZCNT },
    287   { "-mtbm",		OPTION_MASK_ISA_TBM },
    288   { "-mpopcnt",		OPTION_MASK_ISA_POPCNT },
    289   { "-msahf",		OPTION_MASK_ISA_SAHF },
    290   { "-mcrc32",		OPTION_MASK_ISA_CRC32 },
    291   { "-mfsgsbase",	OPTION_MASK_ISA_FSGSBASE },
    292   { "-mrdrnd",		OPTION_MASK_ISA_RDRND },
    293   { "-mpku",		OPTION_MASK_ISA_PKU },
    294   { "-mlwp",		OPTION_MASK_ISA_LWP },
    295   { "-mfxsr",		OPTION_MASK_ISA_FXSR },
    296   { "-mclwb",		OPTION_MASK_ISA_CLWB },
    297   { "-mshstk",		OPTION_MASK_ISA_SHSTK },
    298   { "-mmovdiri",	OPTION_MASK_ISA_MOVDIRI }
    299 };
    300 
    301 /* Return 1 if TRAIT NAME is present in the OpenMP context's
    302    device trait set, return 0 if not present in any OpenMP context in the
    303    whole translation unit, or -1 if not present in the current OpenMP context
    304    but might be present in another OpenMP context in the same TU.  */
    305 
    306 int
    307 ix86_omp_device_kind_arch_isa (enum omp_device_kind_arch_isa trait,
    308 			       const char *name)
    309 {
    310   switch (trait)
    311     {
    312     case omp_device_kind:
    313       return strcmp (name, "cpu") == 0;
    314     case omp_device_arch:
    315 #ifdef ACCEL_COMPILER
    316       if (strcmp (name, "intel_mic") == 0)
    317 	return 1;
    318 #endif
    319       if (strcmp (name, "x86") == 0)
    320 	return 1;
    321       if (TARGET_64BIT)
    322 	{
    323 	  if (TARGET_X32)
    324 	    return strcmp (name, "x32") == 0;
    325 	  else
    326 	    return strcmp (name, "x86_64") == 0;
    327 	}
    328       if (strcmp (name, "ia32") == 0 || strcmp (name, "i386") == 0)
    329 	return 1;
    330       if (strcmp (name, "i486") == 0)
    331 	return ix86_arch != PROCESSOR_I386 ? 1 : -1;
    332       if (strcmp (name, "i586") == 0)
    333 	return (ix86_arch != PROCESSOR_I386
    334 		&& ix86_arch != PROCESSOR_I486) ? 1 : -1;
    335       if (strcmp (name, "i686") == 0)
    336 	return (ix86_arch != PROCESSOR_I386
    337 		&& ix86_arch != PROCESSOR_I486
    338 		&& ix86_arch != PROCESSOR_LAKEMONT
    339 		&& ix86_arch != PROCESSOR_PENTIUM) ? 1 : -1;
    340       return 0;
    341     case omp_device_isa:
    342       for (int i = 0; i < 2; i++)
    343 	{
    344 	  struct ix86_target_opts *opts = i ? isa2_opts : isa_opts;
    345 	  size_t nopts = i ? ARRAY_SIZE (isa2_opts) : ARRAY_SIZE (isa_opts);
    346 	  HOST_WIDE_INT mask = i ? ix86_isa_flags2 : ix86_isa_flags;
    347 	  for (size_t n = 0; n < nopts; n++)
    348 	    {
    349 	      /* Handle sse4 as an alias to sse4.2.  */
    350 	      if (opts[n].mask == OPTION_MASK_ISA_SSE4_2)
    351 		{
    352 		  if (strcmp (name, "sse4") == 0)
    353 		    return (mask & opts[n].mask) != 0 ? 1 : -1;
    354 		}
    355 	      if (strcmp (name, opts[n].option + 2) == 0)
    356 		return (mask & opts[n].mask) != 0 ? 1 : -1;
    357 	    }
    358 	}
    359       return 0;
    360     default:
    361       gcc_unreachable ();
    362     }
    363 }
    364 
    365 /* Return a string that documents the current -m options.  The caller is
    366    responsible for freeing the string.  */
    367 
    368 char *
    369 ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
    370 		    int flags, int flags2,
    371 		    const char *arch, const char *tune,
    372 		    enum fpmath_unit fpmath,
    373 		    enum prefer_vector_width pvw,
    374 		    enum prefer_vector_width move_max,
    375 		    enum prefer_vector_width store_max,
    376 		    bool add_nl_p, bool add_abi_p)
    377 {
    378   /* Flag options.  */
    379   static struct ix86_target_opts flag_opts[] =
    380   {
    381     { "-m128bit-long-double",		MASK_128BIT_LONG_DOUBLE },
    382     { "-mlong-double-128",		MASK_LONG_DOUBLE_128 },
    383     { "-mlong-double-64",		MASK_LONG_DOUBLE_64 },
    384     { "-m80387",			MASK_80387 },
    385     { "-maccumulate-outgoing-args",	MASK_ACCUMULATE_OUTGOING_ARGS },
    386     { "-malign-double",			MASK_ALIGN_DOUBLE },
    387     { "-mcld",				MASK_CLD },
    388     { "-mfp-ret-in-387",		MASK_FLOAT_RETURNS },
    389     { "-mieee-fp",			MASK_IEEE_FP },
    390     { "-minline-all-stringops",		MASK_INLINE_ALL_STRINGOPS },
    391     { "-minline-stringops-dynamically",	MASK_INLINE_STRINGOPS_DYNAMICALLY },
    392     { "-mms-bitfields",			MASK_MS_BITFIELD_LAYOUT },
    393     { "-mno-align-stringops",		MASK_NO_ALIGN_STRINGOPS },
    394     { "-mno-fancy-math-387",		MASK_NO_FANCY_MATH_387 },
    395     { "-mno-push-args",			MASK_NO_PUSH_ARGS },
    396     { "-mno-red-zone",			MASK_NO_RED_ZONE },
    397     { "-momit-leaf-frame-pointer",	MASK_OMIT_LEAF_FRAME_POINTER },
    398     { "-mrecip",			MASK_RECIP },
    399     { "-mrtd",				MASK_RTD },
    400     { "-msseregparm",			MASK_SSEREGPARM },
    401     { "-mstack-arg-probe",		MASK_STACK_PROBE },
    402     { "-mtls-direct-seg-refs",		MASK_TLS_DIRECT_SEG_REFS },
    403     { "-mvect8-ret-in-mem",		MASK_VECT8_RETURNS },
    404     { "-m8bit-idiv",			MASK_USE_8BIT_IDIV },
    405     { "-mvzeroupper",			MASK_VZEROUPPER },
    406     { "-mstv",				MASK_STV },
    407     { "-mavx256-split-unaligned-load",	MASK_AVX256_SPLIT_UNALIGNED_LOAD },
    408     { "-mavx256-split-unaligned-store",	MASK_AVX256_SPLIT_UNALIGNED_STORE },
    409     { "-mcall-ms2sysv-xlogues",		MASK_CALL_MS2SYSV_XLOGUES },
    410     { "-mrelax-cmpxchg-loop",		MASK_RELAX_CMPXCHG_LOOP }
    411   };
    412 
    413   /* Additional flag options.  */
    414   static struct ix86_target_opts flag2_opts[] =
    415   {
    416     { "-mgeneral-regs-only",		OPTION_MASK_GENERAL_REGS_ONLY }
    417   };
    418 
    419   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (isa2_opts)
    420 		   + ARRAY_SIZE (flag_opts) + ARRAY_SIZE (flag2_opts) + 6][2];
    421 
    422   char isa_other[40];
    423   char isa2_other[40];
    424   char flags_other[40];
    425   char flags2_other[40];
    426   unsigned num = 0;
    427   unsigned i, j;
    428   char *ret;
    429   char *ptr;
    430   size_t len;
    431   size_t line_len;
    432   size_t sep_len;
    433   const char *abi;
    434 
    435   memset (opts, '\0', sizeof (opts));
    436 
    437   /* Add -march= option.  */
    438   if (arch)
    439     {
    440       opts[num][0] = "-march=";
    441       opts[num++][1] = arch;
    442     }
    443 
    444   /* Add -mtune= option.  */
    445   if (tune)
    446     {
    447       opts[num][0] = "-mtune=";
    448       opts[num++][1] = tune;
    449     }
    450 
    451   /* Add -m32/-m64/-mx32.  */
    452   if (add_abi_p)
    453     {
    454       if ((isa & OPTION_MASK_ISA_64BIT) != 0)
    455 	{
    456 	  if ((isa & OPTION_MASK_ABI_64) != 0)
    457 	    abi = "-m64";
    458 	  else
    459 	    abi = "-mx32";
    460 	}
    461       else
    462 	abi = "-m32";
    463       opts[num++][0] = abi;
    464     }
    465   isa &= ~(OPTION_MASK_ISA_64BIT | OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
    466 
    467   /* Pick out the options in isa2 options.  */
    468   for (i = 0; i < ARRAY_SIZE (isa2_opts); i++)
    469     {
    470       if ((isa2 & isa2_opts[i].mask) != 0)
    471 	{
    472 	  opts[num++][0] = isa2_opts[i].option;
    473 	  isa2 &= ~ isa2_opts[i].mask;
    474 	}
    475     }
    476 
    477   if (isa2 && add_nl_p)
    478     {
    479       opts[num++][0] = isa2_other;
    480       sprintf (isa2_other, "(other isa2: %#" HOST_WIDE_INT_PRINT "x)", isa2);
    481     }
    482 
    483   /* Pick out the options in isa options.  */
    484   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
    485     {
    486       if ((isa & isa_opts[i].mask) != 0)
    487 	{
    488 	  opts[num++][0] = isa_opts[i].option;
    489 	  isa &= ~ isa_opts[i].mask;
    490 	}
    491     }
    492 
    493   if (isa && add_nl_p)
    494     {
    495       opts[num++][0] = isa_other;
    496       sprintf (isa_other, "(other isa: %#" HOST_WIDE_INT_PRINT "x)", isa);
    497     }
    498 
    499   /* Add flag options.  */
    500   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
    501     {
    502       if ((flags & flag_opts[i].mask) != 0)
    503 	{
    504 	  opts[num++][0] = flag_opts[i].option;
    505 	  flags &= ~ flag_opts[i].mask;
    506 	}
    507     }
    508 
    509   if (flags && add_nl_p)
    510     {
    511       opts[num++][0] = flags_other;
    512       sprintf (flags_other, "(other flags: %#x)", flags);
    513     }
    514 
    515     /* Add additional flag options.  */
    516   for (i = 0; i < ARRAY_SIZE (flag2_opts); i++)
    517     {
    518       if ((flags2 & flag2_opts[i].mask) != 0)
    519 	{
    520 	  opts[num++][0] = flag2_opts[i].option;
    521 	  flags2 &= ~ flag2_opts[i].mask;
    522 	}
    523     }
    524 
    525   if (flags2 && add_nl_p)
    526     {
    527       opts[num++][0] = flags2_other;
    528       sprintf (flags2_other, "(other flags2: %#x)", flags2);
    529     }
    530 
    531   /* Add -mfpmath= option.  */
    532   if (fpmath)
    533     {
    534       opts[num][0] = "-mfpmath=";
    535       switch ((int) fpmath)
    536 	{
    537 	case FPMATH_387:
    538 	  opts[num++][1] = "387";
    539 	  break;
    540 
    541 	case FPMATH_SSE:
    542 	  opts[num++][1] = "sse";
    543 	  break;
    544 
    545 	case FPMATH_387 | FPMATH_SSE:
    546 	  opts[num++][1] = "sse+387";
    547 	  break;
    548 
    549 	default:
    550 	  gcc_unreachable ();
    551 	}
    552     }
    553 
    554   auto add_vector_width = [&opts, &num] (prefer_vector_width pvw,
    555 					 const char *cmd)
    556     {
    557       opts[num][0] = cmd;
    558       switch ((int) pvw)
    559 	{
    560 	case PVW_AVX128:
    561 	  opts[num++][1] = "128";
    562 	  break;
    563 
    564 	case PVW_AVX256:
    565 	  opts[num++][1] = "256";
    566 	  break;
    567 
    568 	case PVW_AVX512:
    569 	  opts[num++][1] = "512";
    570 	  break;
    571 
    572 	default:
    573 	  gcc_unreachable ();
    574 	}
    575     };
    576 
    577   /* Add -mprefer-vector-width= option.  */
    578   if (pvw)
    579     add_vector_width (pvw, "-mprefer-vector-width=");
    580 
    581   /* Add -mmove-max= option.  */
    582   if (move_max)
    583     add_vector_width (move_max, "-mmove-max=");
    584 
    585   /* Add -mstore-max= option.  */
    586   if (store_max)
    587     add_vector_width (store_max, "-mstore-max=");
    588 
    589   /* Any options?  */
    590   if (num == 0)
    591     return NULL;
    592 
    593   gcc_assert (num < ARRAY_SIZE (opts));
    594 
    595   /* Size the string.  */
    596   len = 0;
    597   sep_len = (add_nl_p) ? 3 : 1;
    598   for (i = 0; i < num; i++)
    599     {
    600       len += sep_len;
    601       for (j = 0; j < 2; j++)
    602 	if (opts[i][j])
    603 	  len += strlen (opts[i][j]);
    604     }
    605 
    606   /* Build the string.  */
    607   ret = ptr = (char *) xmalloc (len);
    608   line_len = 0;
    609 
    610   for (i = 0; i < num; i++)
    611     {
    612       size_t len2[2];
    613 
    614       for (j = 0; j < 2; j++)
    615 	len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
    616 
    617       if (i != 0)
    618 	{
    619 	  *ptr++ = ' ';
    620 	  line_len++;
    621 
    622 	  if (add_nl_p && line_len + len2[0] + len2[1] > 70)
    623 	    {
    624 	      *ptr++ = '\\';
    625 	      *ptr++ = '\n';
    626 	      line_len = 0;
    627 	    }
    628 	}
    629 
    630       for (j = 0; j < 2; j++)
    631 	if (opts[i][j])
    632 	  {
    633 	    memcpy (ptr, opts[i][j], len2[j]);
    634 	    ptr += len2[j];
    635 	    line_len += len2[j];
    636 	  }
    637     }
    638 
    639   *ptr = '\0';
    640   gcc_assert (ret + len >= ptr);
    641 
    642   return ret;
    643 }
    644 
    645 /* Function that is callable from the debugger to print the current
    646    options.  */
    647 void ATTRIBUTE_UNUSED
    648 ix86_debug_options (void)
    649 {
    650   char *opts = ix86_target_string (ix86_isa_flags, ix86_isa_flags2,
    651 				   target_flags, ix86_target_flags,
    652 				   ix86_arch_string, ix86_tune_string,
    653 				   ix86_fpmath, prefer_vector_width_type,
    654 				   ix86_move_max, ix86_store_max,
    655 				   true, true);
    656 
    657   if (opts)
    658     {
    659       fprintf (stderr, "%s\n\n", opts);
    660       free (opts);
    661     }
    662   else
    663     fputs ("<no options>\n\n", stderr);
    664 
    665   return;
    666 }
    667 
    668 /* Save the current options */
    669 
    670 void
    671 ix86_function_specific_save (struct cl_target_option *ptr,
    672 			     struct gcc_options *opts,
    673 			     struct gcc_options */* opts_set */)
    674 {
    675   ptr->arch = ix86_arch;
    676   ptr->schedule = ix86_schedule;
    677   ptr->prefetch_sse = ix86_prefetch_sse;
    678   ptr->tune = ix86_tune;
    679   ptr->branch_cost = ix86_branch_cost;
    680   ptr->tune_defaulted = ix86_tune_defaulted;
    681   ptr->arch_specified = ix86_arch_specified;
    682   ptr->x_ix86_isa_flags_explicit = opts->x_ix86_isa_flags_explicit;
    683   ptr->x_ix86_isa_flags2_explicit = opts->x_ix86_isa_flags2_explicit;
    684   ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit;
    685   ptr->x_ix86_arch_string = opts->x_ix86_arch_string;
    686   ptr->x_ix86_tune_string = opts->x_ix86_tune_string;
    687   ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect;
    688   ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost;
    689   ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes;
    690   ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer;
    691   ptr->x_ix86_force_drap = opts->x_ix86_force_drap;
    692   ptr->x_ix86_recip_name = opts->x_ix86_recip_name;
    693   ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold;
    694   ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx;
    695   ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard;
    696   ptr->x_ix86_stringop_alg = opts->x_ix86_stringop_alg;
    697   ptr->x_ix86_tls_dialect = opts->x_ix86_tls_dialect;
    698   ptr->x_ix86_tune_ctrl_string = opts->x_ix86_tune_ctrl_string;
    699   ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy;
    700   ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy;
    701   ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default;
    702 
    703   /* The fields are char but the variables are not; make sure the
    704      values fit in the fields.  */
    705   gcc_assert (ptr->arch == ix86_arch);
    706   gcc_assert (ptr->schedule == ix86_schedule);
    707   gcc_assert (ptr->tune == ix86_tune);
    708   gcc_assert (ptr->branch_cost == ix86_branch_cost);
    709 }
    710 
    711 /* Feature tests against the various architecture variations, used to create
    712    ix86_arch_features based on the processor mask.  */
    713 static unsigned HOST_WIDE_INT initial_ix86_arch_features[X86_ARCH_LAST] = {
    714   /* X86_ARCH_CMOV: Conditional move was added for pentiumpro.  */
    715   ~(m_386 | m_486 | m_PENT | m_LAKEMONT | m_K6),
    716 
    717   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
    718   ~m_386,
    719 
    720   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
    721   ~(m_386 | m_486),
    722 
    723   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
    724   ~m_386,
    725 
    726   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
    727   ~m_386,
    728 };
    729 
    730 /* This table must be in sync with enum processor_type in i386.h.  */
    731 static const struct processor_costs *processor_cost_table[] =
    732 {
    733   &generic_cost,
    734   &i386_cost,
    735   &i486_cost,
    736   &pentium_cost,
    737   &lakemont_cost,
    738   &pentiumpro_cost,
    739   &pentium4_cost,
    740   &nocona_cost,
    741   &core_cost,
    742   &core_cost,
    743   &core_cost,
    744   &core_cost,
    745   &atom_cost,
    746   &slm_cost,
    747   &slm_cost,
    748   &slm_cost,
    749   &tremont_cost,
    750   &slm_cost,
    751   &slm_cost,
    752   &skylake_cost,
    753   &skylake_cost,
    754   &icelake_cost,
    755   &icelake_cost,
    756   &icelake_cost,
    757   &skylake_cost,
    758   &icelake_cost,
    759   &skylake_cost,
    760   &icelake_cost,
    761   &alderlake_cost,
    762   &icelake_cost,
    763   &intel_cost,
    764   &geode_cost,
    765   &k6_cost,
    766   &athlon_cost,
    767   &k8_cost,
    768   &amdfam10_cost,
    769   &bdver_cost,
    770   &bdver_cost,
    771   &bdver_cost,
    772   &bdver_cost,
    773   &btver1_cost,
    774   &btver2_cost,
    775   &znver1_cost,
    776   &znver2_cost,
    777   &znver3_cost,
    778   &znver4_cost,
    779   &znver5_cost
    780 };
    781 
    782 /* Guarantee that the array is aligned with enum processor_type.  */
    783 STATIC_ASSERT (ARRAY_SIZE (processor_cost_table) == PROCESSOR_max);
    784 
    785 static bool
    786 ix86_option_override_internal (bool main_args_p,
    787 			       struct gcc_options *opts,
    788 			       struct gcc_options *opts_set);
    789 static void
    790 set_ix86_tune_features (struct gcc_options *opts,
    791 			enum processor_type ix86_tune, bool dump);
    792 
    793 /* Restore the current options */
    794 
    795 void
    796 ix86_function_specific_restore (struct gcc_options *opts,
    797 				struct gcc_options */* opts_set */,
    798 				struct cl_target_option *ptr)
    799 {
    800   enum processor_type old_tune = ix86_tune;
    801   enum processor_type old_arch = ix86_arch;
    802   unsigned HOST_WIDE_INT ix86_arch_mask;
    803   int i;
    804 
    805   /* We don't change -fPIC.  */
    806   opts->x_flag_pic = flag_pic;
    807 
    808   ix86_arch = (enum processor_type) ptr->arch;
    809   ix86_schedule = (enum attr_cpu) ptr->schedule;
    810   ix86_tune = (enum processor_type) ptr->tune;
    811   ix86_prefetch_sse = ptr->prefetch_sse;
    812   ix86_tune_defaulted = ptr->tune_defaulted;
    813   ix86_arch_specified = ptr->arch_specified;
    814   opts->x_ix86_isa_flags_explicit = ptr->x_ix86_isa_flags_explicit;
    815   opts->x_ix86_isa_flags2_explicit = ptr->x_ix86_isa_flags2_explicit;
    816   opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit;
    817   opts->x_ix86_arch_string = ptr->x_ix86_arch_string;
    818   opts->x_ix86_tune_string = ptr->x_ix86_tune_string;
    819   opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect;
    820   opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost;
    821   opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes;
    822   opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer;
    823   opts->x_ix86_force_drap = ptr->x_ix86_force_drap;
    824   opts->x_ix86_recip_name = ptr->x_ix86_recip_name;
    825   opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold;
    826   opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx;
    827   opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard;
    828   opts->x_ix86_stringop_alg = ptr->x_ix86_stringop_alg;
    829   opts->x_ix86_tls_dialect = ptr->x_ix86_tls_dialect;
    830   opts->x_ix86_tune_ctrl_string = ptr->x_ix86_tune_ctrl_string;
    831   opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy;
    832   opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy;
    833   opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default;
    834   ix86_tune_cost = processor_cost_table[ix86_tune];
    835   /* TODO: ix86_cost should be chosen at instruction or function granuality
    836      so for cold code we use size_cost even in !optimize_size compilation.  */
    837   if (opts->x_optimize_size)
    838     ix86_cost = &ix86_size_cost;
    839   else
    840     ix86_cost = ix86_tune_cost;
    841 
    842   /* Recreate the arch feature tests if the arch changed */
    843   if (old_arch != ix86_arch)
    844     {
    845       ix86_arch_mask = HOST_WIDE_INT_1U << ix86_arch;
    846       for (i = 0; i < X86_ARCH_LAST; ++i)
    847 	ix86_arch_features[i]
    848 	  = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
    849     }
    850 
    851   /* Recreate the tune optimization tests */
    852   if (old_tune != ix86_tune)
    853     set_ix86_tune_features (opts, ix86_tune, false);
    854 }
    855 
    856 /* Adjust target options after streaming them in.  This is mainly about
    857    reconciling them with global options.  */
    858 
    859 void
    860 ix86_function_specific_post_stream_in (struct cl_target_option *ptr)
    861 {
    862   /* flag_pic is a global option, but ix86_cmodel is target saved option
    863      partly computed from flag_pic.  If flag_pic is on, adjust x_ix86_cmodel
    864      for PIC, or error out.  */
    865   if (flag_pic)
    866     switch (ptr->x_ix86_cmodel)
    867       {
    868       case CM_SMALL:
    869 	ptr->x_ix86_cmodel = CM_SMALL_PIC;
    870 	break;
    871 
    872       case CM_MEDIUM:
    873 	ptr->x_ix86_cmodel = CM_MEDIUM_PIC;
    874 	break;
    875 
    876       case CM_LARGE:
    877 	ptr->x_ix86_cmodel = CM_LARGE_PIC;
    878 	break;
    879 
    880       case CM_KERNEL:
    881 	error ("code model %s does not support PIC mode", "kernel");
    882 	break;
    883 
    884       default:
    885 	break;
    886       }
    887   else
    888     switch (ptr->x_ix86_cmodel)
    889       {
    890       case CM_SMALL_PIC:
    891 	ptr->x_ix86_cmodel = CM_SMALL;
    892 	break;
    893 
    894       case CM_MEDIUM_PIC:
    895 	ptr->x_ix86_cmodel = CM_MEDIUM;
    896 	break;
    897 
    898       case CM_LARGE_PIC:
    899 	ptr->x_ix86_cmodel = CM_LARGE;
    900 	break;
    901 
    902       default:
    903 	break;
    904       }
    905 }
    906 
    907 /* Print the current options */
    908 
    909 void
    910 ix86_function_specific_print (FILE *file, int indent,
    911 			      struct cl_target_option *ptr)
    912 {
    913   char *target_string
    914     = ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_ix86_isa_flags2,
    915 			  ptr->x_target_flags, ptr->x_ix86_target_flags,
    916 			  NULL, NULL, ptr->x_ix86_fpmath,
    917 			  ptr->x_prefer_vector_width_type,
    918 			  ptr->x_ix86_move_max, ptr->x_ix86_store_max,
    919 			  false, true);
    920 
    921   gcc_assert (ptr->arch < PROCESSOR_max);
    922   fprintf (file, "%*sarch = %d (%s)\n",
    923 	   indent, "",
    924 	   ptr->arch, processor_names[ptr->arch]);
    925 
    926   gcc_assert (ptr->tune < PROCESSOR_max);
    927   fprintf (file, "%*stune = %d (%s)\n",
    928 	   indent, "",
    929 	   ptr->tune, processor_names[ptr->tune]);
    930 
    931   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
    932 
    933   if (target_string)
    934     {
    935       fprintf (file, "%*s%s\n", indent, "", target_string);
    936       free (target_string);
    937     }
    938 }
    939 
    940 
    941 /* Inner function to process the attribute((target(...))), take an argument and
    943    set the current options from the argument. If we have a list, recursively go
    944    over the list.  */
    945 
    946 static bool
    947 ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[],
    948 				     struct gcc_options *opts,
    949 				     struct gcc_options *opts_set,
    950 				     struct gcc_options *enum_opts_set,
    951 				     bool target_clone_attr)
    952 {
    953   char *next_optstr;
    954   bool ret = true;
    955 
    956 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
    957 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
    958 #define IX86_ATTR_ENUM(S,O)  { S, sizeof (S)-1, ix86_opt_enum, O, 0 }
    959 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
    960 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
    961 #define IX86_ATTR_IX86_YES(S,O,M) \
    962   { S, sizeof (S)-1, ix86_opt_ix86_yes, O, M }
    963 #define IX86_ATTR_IX86_NO(S,O,M) \
    964   { S, sizeof (S)-1, ix86_opt_ix86_no,  O, M }
    965 
    966   enum ix86_opt_type
    967   {
    968     ix86_opt_unknown,
    969     ix86_opt_yes,
    970     ix86_opt_no,
    971     ix86_opt_ix86_yes,
    972     ix86_opt_ix86_no,
    973     ix86_opt_str,
    974     ix86_opt_enum,
    975     ix86_opt_isa
    976   };
    977 
    978   static const struct
    979   {
    980     const char *string;
    981     size_t len;
    982     enum ix86_opt_type type;
    983     int opt;
    984     int mask;
    985   } attrs[] = {
    986     /* isa options */
    987     IX86_ATTR_ISA ("pconfig",	OPT_mpconfig),
    988     IX86_ATTR_ISA ("wbnoinvd",	OPT_mwbnoinvd),
    989     IX86_ATTR_ISA ("sgx",	OPT_msgx),
    990     IX86_ATTR_ISA ("avx5124fmaps", OPT_mavx5124fmaps),
    991     IX86_ATTR_ISA ("avx5124vnniw", OPT_mavx5124vnniw),
    992     IX86_ATTR_ISA ("avx512vpopcntdq", OPT_mavx512vpopcntdq),
    993     IX86_ATTR_ISA ("avx512vbmi2", OPT_mavx512vbmi2),
    994     IX86_ATTR_ISA ("avx512vnni", OPT_mavx512vnni),
    995     IX86_ATTR_ISA ("avx512bitalg", OPT_mavx512bitalg),
    996     IX86_ATTR_ISA ("avx512vp2intersect", OPT_mavx512vp2intersect),
    997 
    998     IX86_ATTR_ISA ("avx512vbmi", OPT_mavx512vbmi),
    999     IX86_ATTR_ISA ("avx512ifma", OPT_mavx512ifma),
   1000     IX86_ATTR_ISA ("avx512vl",	OPT_mavx512vl),
   1001     IX86_ATTR_ISA ("avx512bw",	OPT_mavx512bw),
   1002     IX86_ATTR_ISA ("avx512dq",	OPT_mavx512dq),
   1003     IX86_ATTR_ISA ("avx512er",	OPT_mavx512er),
   1004     IX86_ATTR_ISA ("avx512pf",	OPT_mavx512pf),
   1005     IX86_ATTR_ISA ("avx512cd",	OPT_mavx512cd),
   1006     IX86_ATTR_ISA ("avx512f",	OPT_mavx512f),
   1007     IX86_ATTR_ISA ("avx2",	OPT_mavx2),
   1008     IX86_ATTR_ISA ("fma",	OPT_mfma),
   1009     IX86_ATTR_ISA ("xop",	OPT_mxop),
   1010     IX86_ATTR_ISA ("fma4",	OPT_mfma4),
   1011     IX86_ATTR_ISA ("f16c",	OPT_mf16c),
   1012     IX86_ATTR_ISA ("avx",	OPT_mavx),
   1013     IX86_ATTR_ISA ("sse4",	OPT_msse4),
   1014     IX86_ATTR_ISA ("sse4.2",	OPT_msse4_2),
   1015     IX86_ATTR_ISA ("sse4.1",	OPT_msse4_1),
   1016     IX86_ATTR_ISA ("sse4a",	OPT_msse4a),
   1017     IX86_ATTR_ISA ("ssse3",	OPT_mssse3),
   1018     IX86_ATTR_ISA ("sse3",	OPT_msse3),
   1019     IX86_ATTR_ISA ("aes",	OPT_maes),
   1020     IX86_ATTR_ISA ("sha",	OPT_msha),
   1021     IX86_ATTR_ISA ("pclmul",	OPT_mpclmul),
   1022     IX86_ATTR_ISA ("sse2",	OPT_msse2),
   1023     IX86_ATTR_ISA ("sse",	OPT_msse),
   1024     IX86_ATTR_ISA ("3dnowa",	OPT_m3dnowa),
   1025     IX86_ATTR_ISA ("3dnow",	OPT_m3dnow),
   1026     IX86_ATTR_ISA ("mmx",	OPT_mmmx),
   1027     IX86_ATTR_ISA ("rtm",	OPT_mrtm),
   1028     IX86_ATTR_ISA ("prfchw",	OPT_mprfchw),
   1029     IX86_ATTR_ISA ("rdseed",	OPT_mrdseed),
   1030     IX86_ATTR_ISA ("adx",	OPT_madx),
   1031     IX86_ATTR_ISA ("prefetchwt1", OPT_mprefetchwt1),
   1032     IX86_ATTR_ISA ("clflushopt", OPT_mclflushopt),
   1033     IX86_ATTR_ISA ("xsaves",	OPT_mxsaves),
   1034     IX86_ATTR_ISA ("xsavec",	OPT_mxsavec),
   1035     IX86_ATTR_ISA ("xsaveopt",	OPT_mxsaveopt),
   1036     IX86_ATTR_ISA ("xsave",	OPT_mxsave),
   1037     IX86_ATTR_ISA ("abm",	OPT_mabm),
   1038     IX86_ATTR_ISA ("bmi",	OPT_mbmi),
   1039     IX86_ATTR_ISA ("bmi2",	OPT_mbmi2),
   1040     IX86_ATTR_ISA ("lzcnt",	OPT_mlzcnt),
   1041     IX86_ATTR_ISA ("tbm",	OPT_mtbm),
   1042     IX86_ATTR_ISA ("popcnt",	OPT_mpopcnt),
   1043     IX86_ATTR_ISA ("cx16",	OPT_mcx16),
   1044     IX86_ATTR_ISA ("sahf",	OPT_msahf),
   1045     IX86_ATTR_ISA ("movbe",	OPT_mmovbe),
   1046     IX86_ATTR_ISA ("crc32",	OPT_mcrc32),
   1047     IX86_ATTR_ISA ("fsgsbase",	OPT_mfsgsbase),
   1048     IX86_ATTR_ISA ("rdrnd",	OPT_mrdrnd),
   1049     IX86_ATTR_ISA ("mwaitx",	OPT_mmwaitx),
   1050     IX86_ATTR_ISA ("mwait",	OPT_mmwait),
   1051     IX86_ATTR_ISA ("clzero",	OPT_mclzero),
   1052     IX86_ATTR_ISA ("pku",	OPT_mpku),
   1053     IX86_ATTR_ISA ("lwp",	OPT_mlwp),
   1054     IX86_ATTR_ISA ("hle",	OPT_mhle),
   1055     IX86_ATTR_ISA ("fxsr",	OPT_mfxsr),
   1056     IX86_ATTR_ISA ("clwb",	OPT_mclwb),
   1057     IX86_ATTR_ISA ("rdpid",	OPT_mrdpid),
   1058     IX86_ATTR_ISA ("gfni",	OPT_mgfni),
   1059     IX86_ATTR_ISA ("shstk",	OPT_mshstk),
   1060     IX86_ATTR_ISA ("vaes",	OPT_mvaes),
   1061     IX86_ATTR_ISA ("vpclmulqdq", OPT_mvpclmulqdq),
   1062     IX86_ATTR_ISA ("movdiri", OPT_mmovdiri),
   1063     IX86_ATTR_ISA ("movdir64b", OPT_mmovdir64b),
   1064     IX86_ATTR_ISA ("waitpkg", OPT_mwaitpkg),
   1065     IX86_ATTR_ISA ("cldemote", OPT_mcldemote),
   1066     IX86_ATTR_ISA ("uintr", OPT_muintr),
   1067     IX86_ATTR_ISA ("ptwrite",   OPT_mptwrite),
   1068     IX86_ATTR_ISA ("kl", OPT_mkl),
   1069     IX86_ATTR_ISA ("widekl",	OPT_mwidekl),
   1070     IX86_ATTR_ISA ("avx512bf16",   OPT_mavx512bf16),
   1071     IX86_ATTR_ISA ("enqcmd", OPT_menqcmd),
   1072     IX86_ATTR_ISA ("serialize", OPT_mserialize),
   1073     IX86_ATTR_ISA ("tsxldtrk", OPT_mtsxldtrk),
   1074     IX86_ATTR_ISA ("amx-tile", OPT_mamx_tile),
   1075     IX86_ATTR_ISA ("amx-int8", OPT_mamx_int8),
   1076     IX86_ATTR_ISA ("amx-bf16", OPT_mamx_bf16),
   1077     IX86_ATTR_ISA ("hreset", OPT_mhreset),
   1078     IX86_ATTR_ISA ("avxvnni",   OPT_mavxvnni),
   1079     IX86_ATTR_ISA ("avx512fp16", OPT_mavx512fp16),
   1080 
   1081     /* enum options */
   1082     IX86_ATTR_ENUM ("fpmath=",	OPT_mfpmath_),
   1083     IX86_ATTR_ENUM ("prefer-vector-width=", OPT_mprefer_vector_width_),
   1084 
   1085     /* string options */
   1086     IX86_ATTR_STR ("arch=",	IX86_FUNCTION_SPECIFIC_ARCH),
   1087     IX86_ATTR_STR ("tune=",	IX86_FUNCTION_SPECIFIC_TUNE),
   1088 
   1089     /* flag options */
   1090     IX86_ATTR_YES ("cld",
   1091 		   OPT_mcld,
   1092 		   MASK_CLD),
   1093 
   1094     IX86_ATTR_NO ("fancy-math-387",
   1095 		  OPT_mfancy_math_387,
   1096 		  MASK_NO_FANCY_MATH_387),
   1097 
   1098     IX86_ATTR_YES ("ieee-fp",
   1099 		   OPT_mieee_fp,
   1100 		   MASK_IEEE_FP),
   1101 
   1102     IX86_ATTR_YES ("inline-all-stringops",
   1103 		   OPT_minline_all_stringops,
   1104 		   MASK_INLINE_ALL_STRINGOPS),
   1105 
   1106     IX86_ATTR_YES ("inline-stringops-dynamically",
   1107 		   OPT_minline_stringops_dynamically,
   1108 		   MASK_INLINE_STRINGOPS_DYNAMICALLY),
   1109 
   1110     IX86_ATTR_NO ("align-stringops",
   1111 		  OPT_mno_align_stringops,
   1112 		  MASK_NO_ALIGN_STRINGOPS),
   1113 
   1114     IX86_ATTR_YES ("recip",
   1115 		   OPT_mrecip,
   1116 		   MASK_RECIP),
   1117 
   1118     IX86_ATTR_IX86_YES ("general-regs-only",
   1119 			OPT_mgeneral_regs_only,
   1120 			OPTION_MASK_GENERAL_REGS_ONLY),
   1121 
   1122     IX86_ATTR_YES ("relax-cmpxchg-loop",
   1123 		   OPT_mrelax_cmpxchg_loop,
   1124 		   MASK_RELAX_CMPXCHG_LOOP),
   1125   };
   1126 
   1127   location_t loc
   1128     = fndecl == NULL ? UNKNOWN_LOCATION : DECL_SOURCE_LOCATION (fndecl);
   1129   const char *attr_name = target_clone_attr ? "target_clone" : "target";
   1130 
   1131   /* If this is a list, recurse to get the options.  */
   1132   if (TREE_CODE (args) == TREE_LIST)
   1133     {
   1134       for (; args; args = TREE_CHAIN (args))
   1135 	if (TREE_VALUE (args)
   1136 	    && !ix86_valid_target_attribute_inner_p (fndecl, TREE_VALUE (args),
   1137 						     p_strings, opts, opts_set,
   1138 						     enum_opts_set,
   1139 						     target_clone_attr))
   1140 	  ret = false;
   1141 
   1142       return ret;
   1143     }
   1144 
   1145   else if (TREE_CODE (args) != STRING_CST)
   1146     {
   1147       error_at (loc, "attribute %qs argument is not a string", attr_name);
   1148       return false;
   1149     }
   1150 
   1151   /* Handle multiple arguments separated by commas.  */
   1152   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
   1153 
   1154   while (next_optstr && *next_optstr != '\0')
   1155     {
   1156       char *p = next_optstr;
   1157       char *orig_p = p;
   1158       char *comma = strchr (next_optstr, ',');
   1159       size_t len, opt_len;
   1160       int opt;
   1161       bool opt_set_p;
   1162       char ch;
   1163       unsigned i;
   1164       enum ix86_opt_type type = ix86_opt_unknown;
   1165       int mask = 0;
   1166 
   1167       if (comma)
   1168 	{
   1169 	  *comma = '\0';
   1170 	  len = comma - next_optstr;
   1171 	  next_optstr = comma + 1;
   1172 	}
   1173       else
   1174 	{
   1175 	  len = strlen (p);
   1176 	  next_optstr = NULL;
   1177 	}
   1178 
   1179       /* Recognize no-xxx.  */
   1180       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
   1181 	{
   1182 	  opt_set_p = false;
   1183 	  p += 3;
   1184 	  len -= 3;
   1185 	}
   1186       else
   1187 	opt_set_p = true;
   1188 
   1189       /* Find the option.  */
   1190       ch = *p;
   1191       opt = N_OPTS;
   1192       for (i = 0; i < ARRAY_SIZE (attrs); i++)
   1193 	{
   1194 	  type = attrs[i].type;
   1195 	  opt_len = attrs[i].len;
   1196 	  if (ch == attrs[i].string[0]
   1197 	      && ((type != ix86_opt_str && type != ix86_opt_enum)
   1198 		  ? len == opt_len
   1199 		  : len > opt_len)
   1200 	      && memcmp (p, attrs[i].string, opt_len) == 0)
   1201 	    {
   1202 	      opt = attrs[i].opt;
   1203 	      mask = attrs[i].mask;
   1204 	      break;
   1205 	    }
   1206 	}
   1207 
   1208       /* Process the option.  */
   1209       if (opt == N_OPTS)
   1210 	{
   1211 	  error_at (loc, "attribute %qs argument %qs is unknown",
   1212 		    attr_name, orig_p);
   1213 	  ret = false;
   1214 	}
   1215 
   1216       else if (type == ix86_opt_isa)
   1217 	{
   1218 	  struct cl_decoded_option decoded;
   1219 
   1220 	  generate_option (opt, NULL, opt_set_p, CL_TARGET, &decoded);
   1221 	  ix86_handle_option (opts, opts_set,
   1222 			      &decoded, input_location);
   1223 	}
   1224 
   1225       else if (type == ix86_opt_yes || type == ix86_opt_no)
   1226 	{
   1227 	  if (type == ix86_opt_no)
   1228 	    opt_set_p = !opt_set_p;
   1229 
   1230 	  if (opt_set_p)
   1231 	    opts->x_target_flags |= mask;
   1232 	  else
   1233 	    opts->x_target_flags &= ~mask;
   1234 	}
   1235 
   1236       else if (type == ix86_opt_ix86_yes || type == ix86_opt_ix86_no)
   1237 	{
   1238 	  if (mask == OPTION_MASK_GENERAL_REGS_ONLY)
   1239 	    {
   1240 	      if (!opt_set_p)
   1241 		{
   1242 		  error_at (loc, "pragma or attribute %<target(\"%s\")%> "
   1243 			    "does not allow a negated form", p);
   1244 		  return false;
   1245 		}
   1246 
   1247 	      if (type != ix86_opt_ix86_yes)
   1248 		gcc_unreachable ();
   1249 
   1250 	      opts->x_ix86_target_flags |= mask;
   1251 
   1252 	      struct cl_decoded_option decoded;
   1253 	      generate_option (opt, NULL, opt_set_p, CL_TARGET,
   1254 			       &decoded);
   1255 	      ix86_handle_option (opts, opts_set, &decoded,
   1256 				  input_location);
   1257 	    }
   1258 	  else
   1259 	    {
   1260 	      if (type == ix86_opt_ix86_no)
   1261 		opt_set_p = !opt_set_p;
   1262 
   1263 	      if (opt_set_p)
   1264 		opts->x_ix86_target_flags |= mask;
   1265 	      else
   1266 		opts->x_ix86_target_flags &= ~mask;
   1267 	    }
   1268 	}
   1269 
   1270       else if (type == ix86_opt_str)
   1271 	{
   1272 	  if (p_strings[opt])
   1273 	    {
   1274 	      error_at (loc, "attribute value %qs was already specified "
   1275 			"in %qs attribute", orig_p, attr_name);
   1276 	      ret = false;
   1277 	    }
   1278 	  else
   1279 	    {
   1280 	      p_strings[opt] = xstrdup (p + opt_len);
   1281 	      if (opt == IX86_FUNCTION_SPECIFIC_ARCH)
   1282 		{
   1283 		  /* If arch= is set,  clear all bits in x_ix86_isa_flags,
   1284 		     except for ISA_64BIT, ABI_64, ABI_X32, and CODE16
   1285 		     and all bits in x_ix86_isa_flags2.  */
   1286 		  opts->x_ix86_isa_flags &= (OPTION_MASK_ISA_64BIT
   1287 					     | OPTION_MASK_ABI_64
   1288 					     | OPTION_MASK_ABI_X32
   1289 					     | OPTION_MASK_CODE16);
   1290 		  opts->x_ix86_isa_flags_explicit &= (OPTION_MASK_ISA_64BIT
   1291 						      | OPTION_MASK_ABI_64
   1292 						      | OPTION_MASK_ABI_X32
   1293 						      | OPTION_MASK_CODE16);
   1294 		  opts->x_ix86_isa_flags2 = 0;
   1295 		  opts->x_ix86_isa_flags2_explicit = 0;
   1296 		}
   1297 	    }
   1298 	}
   1299 
   1300       else if (type == ix86_opt_enum)
   1301 	{
   1302 	  bool arg_ok;
   1303 	  int value;
   1304 
   1305 	  arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET);
   1306 	  if (arg_ok)
   1307 	    set_option (opts, enum_opts_set, opt, value,
   1308 			p + opt_len, DK_UNSPECIFIED, input_location,
   1309 			global_dc);
   1310 	  else
   1311 	    {
   1312 	      error_at (loc, "attribute value %qs is unknown in %qs attribute",
   1313 			orig_p, attr_name);
   1314 	      ret = false;
   1315 	    }
   1316 	}
   1317 
   1318       else
   1319 	gcc_unreachable ();
   1320     }
   1321 
   1322   return ret;
   1323 }
   1324 
   1325 /* Release allocated strings.  */
   1326 static void
   1327 release_options_strings (char **option_strings)
   1328 {
   1329   /* Free up memory allocated to hold the strings */
   1330   for (unsigned i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
   1331     free (option_strings[i]);
   1332 }
   1333 
   1334 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
   1335 
   1336 tree
   1337 ix86_valid_target_attribute_tree (tree fndecl, tree args,
   1338 				  struct gcc_options *opts,
   1339 				  struct gcc_options *opts_set,
   1340 				  bool target_clone_attr)
   1341 {
   1342   const char *orig_arch_string = opts->x_ix86_arch_string;
   1343   const char *orig_tune_string = opts->x_ix86_tune_string;
   1344   enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath;
   1345   enum prefer_vector_width orig_pvw_set = opts_set->x_prefer_vector_width_type;
   1346   enum prefer_vector_width orig_ix86_move_max_set
   1347     = opts_set->x_ix86_move_max;
   1348   enum prefer_vector_width orig_ix86_store_max_set
   1349     = opts_set->x_ix86_store_max;
   1350   int orig_tune_defaulted = ix86_tune_defaulted;
   1351   int orig_arch_specified = ix86_arch_specified;
   1352   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL };
   1353   tree t = NULL_TREE;
   1354   struct cl_target_option *def
   1355     = TREE_TARGET_OPTION (target_option_default_node);
   1356   struct gcc_options enum_opts_set;
   1357 
   1358   memset (&enum_opts_set, 0, sizeof (enum_opts_set));
   1359 
   1360   /* Process each of the options on the chain.  */
   1361   if (!ix86_valid_target_attribute_inner_p (fndecl, args, option_strings, opts,
   1362 					    opts_set, &enum_opts_set,
   1363 					    target_clone_attr))
   1364     return error_mark_node;
   1365 
   1366   /* If the changed options are different from the default, rerun
   1367      ix86_option_override_internal, and then save the options away.
   1368      The string options are attribute options, and will be undone
   1369      when we copy the save structure.  */
   1370   if (opts->x_ix86_isa_flags != def->x_ix86_isa_flags
   1371       || opts->x_ix86_isa_flags2 != def->x_ix86_isa_flags2
   1372       || opts->x_target_flags != def->x_target_flags
   1373       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
   1374       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
   1375       || enum_opts_set.x_ix86_fpmath
   1376       || enum_opts_set.x_prefer_vector_width_type)
   1377     {
   1378       /* If we are using the default tune= or arch=, undo the string assigned,
   1379 	 and use the default.  */
   1380       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
   1381 	opts->x_ix86_arch_string
   1382 	  = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]);
   1383       else if (!orig_arch_specified)
   1384 	opts->x_ix86_arch_string = NULL;
   1385 
   1386       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
   1387 	opts->x_ix86_tune_string
   1388 	  = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_TUNE]);
   1389       /* If we have explicit arch string and no tune string specified, set
   1390 	 tune_string to NULL and later it will be overriden by arch_string
   1391 	 so target clones can get proper optimization.  */
   1392       else if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
   1393 	       || orig_tune_defaulted)
   1394 	opts->x_ix86_tune_string = NULL;
   1395 
   1396       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
   1397       if (enum_opts_set.x_ix86_fpmath)
   1398 	opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
   1399       if (enum_opts_set.x_prefer_vector_width_type)
   1400 	opts_set->x_prefer_vector_width_type = (enum prefer_vector_width) 1;
   1401 
   1402       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
   1403       bool r = ix86_option_override_internal (false, opts, opts_set);
   1404       if (!r)
   1405 	{
   1406 	  release_options_strings (option_strings);
   1407 	  return error_mark_node;
   1408 	}
   1409 
   1410       /* Add any builtin functions with the new isa if any.  */
   1411       ix86_add_new_builtins (opts->x_ix86_isa_flags, opts->x_ix86_isa_flags2);
   1412 
   1413       enum excess_precision orig_ix86_excess_precision
   1414 	= opts->x_ix86_excess_precision;
   1415       bool orig_ix86_unsafe_math_optimizations
   1416 	= opts->x_ix86_unsafe_math_optimizations;
   1417       opts->x_ix86_excess_precision = opts->x_flag_excess_precision;
   1418       opts->x_ix86_unsafe_math_optimizations
   1419 	= opts->x_flag_unsafe_math_optimizations;
   1420 
   1421       /* Save the current options unless we are validating options for
   1422 	 #pragma.  */
   1423       t = build_target_option_node (opts, opts_set);
   1424 
   1425       opts->x_ix86_arch_string = orig_arch_string;
   1426       opts->x_ix86_tune_string = orig_tune_string;
   1427       opts_set->x_ix86_fpmath = orig_fpmath_set;
   1428       opts_set->x_prefer_vector_width_type = orig_pvw_set;
   1429       opts_set->x_ix86_move_max = orig_ix86_move_max_set;
   1430       opts_set->x_ix86_store_max = orig_ix86_store_max_set;
   1431       opts->x_ix86_excess_precision = orig_ix86_excess_precision;
   1432       opts->x_ix86_unsafe_math_optimizations
   1433 	= orig_ix86_unsafe_math_optimizations;
   1434 
   1435       release_options_strings (option_strings);
   1436     }
   1437 
   1438   return t;
   1439 }
   1440 
   1441 static GTY(()) tree target_attribute_cache[3];
   1442 
   1443 /* Hook to validate attribute((target("string"))).  */
   1444 
   1445 bool
   1446 ix86_valid_target_attribute_p (tree fndecl,
   1447 			       tree ARG_UNUSED (name),
   1448 			       tree args,
   1449 			       int flags)
   1450 {
   1451   struct gcc_options func_options, func_options_set;
   1452   tree new_target, new_optimize;
   1453   bool ret = true;
   1454 
   1455   /* attribute((target("default"))) does nothing, beyond
   1456      affecting multi-versioning.  */
   1457   if (TREE_VALUE (args)
   1458       && TREE_CODE (TREE_VALUE (args)) == STRING_CST
   1459       && TREE_CHAIN (args) == NULL_TREE
   1460       && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0)
   1461     return true;
   1462 
   1463   if ((DECL_FUNCTION_SPECIFIC_TARGET (fndecl) == target_attribute_cache[1]
   1464        || DECL_FUNCTION_SPECIFIC_TARGET (fndecl) == NULL_TREE)
   1465       && (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl)
   1466 	  == target_attribute_cache[2]
   1467 	  || DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) == NULL_TREE)
   1468       && simple_cst_list_equal (args, target_attribute_cache[0]))
   1469     {
   1470       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = target_attribute_cache[1];
   1471       DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl)
   1472 	= target_attribute_cache[2];
   1473       return true;
   1474     }
   1475 
   1476   tree old_optimize = build_optimization_node (&global_options,
   1477 					       &global_options_set);
   1478 
   1479   /* Get the optimization options of the current function.  */
   1480   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
   1481 
   1482   if (!func_optimize)
   1483     func_optimize = old_optimize;
   1484 
   1485   /* Init func_options.  */
   1486   memset (&func_options, 0, sizeof (func_options));
   1487   init_options_struct (&func_options, NULL);
   1488   lang_hooks.init_options_struct (&func_options);
   1489   memset (&func_options_set, 0, sizeof (func_options_set));
   1490 
   1491   cl_optimization_restore (&func_options, &func_options_set,
   1492 			   TREE_OPTIMIZATION (func_optimize));
   1493 
   1494   /* Initialize func_options to the default before its target options can
   1495      be set.  */
   1496   tree old_target = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
   1497   if (old_target == NULL_TREE)
   1498     old_target = target_option_default_node;
   1499   cl_target_option_restore (&func_options, &func_options_set,
   1500 			    TREE_TARGET_OPTION (old_target));
   1501 
   1502   /* FLAGS == 1 is used for target_clones attribute.  */
   1503   new_target
   1504     = ix86_valid_target_attribute_tree (fndecl, args, &func_options,
   1505 					&func_options_set, flags == 1);
   1506 
   1507   new_optimize = build_optimization_node (&func_options, &func_options_set);
   1508 
   1509   if (new_target == error_mark_node)
   1510     ret = false;
   1511 
   1512   else if (new_target)
   1513     {
   1514       if (DECL_FUNCTION_SPECIFIC_TARGET (fndecl) == NULL_TREE
   1515 	  && DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) == NULL_TREE)
   1516 	{
   1517 	  target_attribute_cache[0] = copy_list (args);
   1518 	  target_attribute_cache[1] = new_target;
   1519 	  target_attribute_cache[2]
   1520 	    = old_optimize != new_optimize ? new_optimize : NULL_TREE;
   1521 	}
   1522 
   1523       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
   1524 
   1525       if (old_optimize != new_optimize)
   1526 	DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
   1527     }
   1528 
   1529   return ret;
   1530 }
   1531 
   1532 const char *stringop_alg_names[] = {
   1533 #define DEF_ALG(alg, name) #name,
   1534 #include "stringop.def"
   1535 #undef DEF_ALG
   1536 };
   1537 
   1538 /* Parse parameter string passed to -mmemcpy-strategy= or -mmemset-strategy=.
   1539    The string is of the following form (or comma separated list of it):
   1540 
   1541      strategy_alg:max_size:[align|noalign]
   1542 
   1543    where the full size range for the strategy is either [0, max_size] or
   1544    [min_size, max_size], in which min_size is the max_size + 1 of the
   1545    preceding range.  The last size range must have max_size == -1.
   1546 
   1547    Examples:
   1548 
   1549     1.
   1550        -mmemcpy-strategy=libcall:-1:noalign
   1551 
   1552       this is equivalent to (for known size memcpy) -mstringop-strategy=libcall
   1553 
   1554 
   1555    2.
   1556       -mmemset-strategy=rep_8byte:16:noalign,vector_loop:2048:align,libcall:-1:noalign
   1557 
   1558       This is to tell the compiler to use the following strategy for memset
   1559       1) when the expected size is between [1, 16], use rep_8byte strategy;
   1560       2) when the size is between [17, 2048], use vector_loop;
   1561       3) when the size is > 2048, use libcall.  */
   1562 
   1563 struct stringop_size_range
   1564 {
   1565   int max;
   1566   stringop_alg alg;
   1567   bool noalign;
   1568 };
   1569 
   1570 static void
   1571 ix86_parse_stringop_strategy_string (char *strategy_str, bool is_memset)
   1572 {
   1573   const struct stringop_algs *default_algs;
   1574   stringop_size_range input_ranges[MAX_STRINGOP_ALGS];
   1575   char *curr_range_str, *next_range_str;
   1576   const char *opt = is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=";
   1577   int i = 0, n = 0;
   1578 
   1579   if (is_memset)
   1580     default_algs = &ix86_cost->memset[TARGET_64BIT != 0];
   1581   else
   1582     default_algs = &ix86_cost->memcpy[TARGET_64BIT != 0];
   1583 
   1584   curr_range_str = strategy_str;
   1585 
   1586   do
   1587     {
   1588       int maxs;
   1589       char alg_name[128];
   1590       char align[16];
   1591       next_range_str = strchr (curr_range_str, ',');
   1592       if (next_range_str)
   1593         *next_range_str++ = '\0';
   1594 
   1595       if (sscanf (curr_range_str, "%20[^:]:%d:%10s", alg_name, &maxs,
   1596 		  align) != 3)
   1597         {
   1598 	  error ("wrong argument %qs to option %qs", curr_range_str, opt);
   1599           return;
   1600         }
   1601 
   1602       if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1))
   1603         {
   1604 	  error ("size ranges of option %qs should be increasing", opt);
   1605           return;
   1606         }
   1607 
   1608       for (i = 0; i < last_alg; i++)
   1609 	if (!strcmp (alg_name, stringop_alg_names[i]))
   1610 	  break;
   1611 
   1612       if (i == last_alg)
   1613         {
   1614 	  error ("wrong strategy name %qs specified for option %qs",
   1615 		 alg_name, opt);
   1616 
   1617 	  auto_vec <const char *> candidates;
   1618 	  for (i = 0; i < last_alg; i++)
   1619 	    if ((stringop_alg) i != rep_prefix_8_byte || TARGET_64BIT)
   1620 	      candidates.safe_push (stringop_alg_names[i]);
   1621 
   1622 	  char *s;
   1623 	  const char *hint
   1624 	    = candidates_list_and_hint (alg_name, s, candidates);
   1625 	  if (hint)
   1626 	    inform (input_location,
   1627 		    "valid arguments to %qs are: %s; did you mean %qs?",
   1628 		    opt, s, hint);
   1629 	  else
   1630 	    inform (input_location, "valid arguments to %qs are: %s",
   1631 		    opt, s);
   1632 	  XDELETEVEC (s);
   1633           return;
   1634         }
   1635 
   1636       if ((stringop_alg) i == rep_prefix_8_byte
   1637 	  && !TARGET_64BIT)
   1638 	{
   1639 	  /* rep; movq isn't available in 32-bit code.  */
   1640 	  error ("strategy name %qs specified for option %qs "
   1641 		 "not supported for 32-bit code", alg_name, opt);
   1642 	  return;
   1643 	}
   1644 
   1645       input_ranges[n].max = maxs;
   1646       input_ranges[n].alg = (stringop_alg) i;
   1647       if (!strcmp (align, "align"))
   1648         input_ranges[n].noalign = false;
   1649       else if (!strcmp (align, "noalign"))
   1650         input_ranges[n].noalign = true;
   1651       else
   1652         {
   1653 	  error ("unknown alignment %qs specified for option %qs", align, opt);
   1654           return;
   1655         }
   1656       n++;
   1657       curr_range_str = next_range_str;
   1658     }
   1659   while (curr_range_str);
   1660 
   1661   if (input_ranges[n - 1].max != -1)
   1662     {
   1663       error ("the max value for the last size range should be -1"
   1664              " for option %qs", opt);
   1665       return;
   1666     }
   1667 
   1668   if (n > MAX_STRINGOP_ALGS)
   1669     {
   1670       error ("too many size ranges specified in option %qs", opt);
   1671       return;
   1672     }
   1673 
   1674   /* Now override the default algs array.  */
   1675   for (i = 0; i < n; i++)
   1676     {
   1677       *const_cast<int *>(&default_algs->size[i].max) = input_ranges[i].max;
   1678       *const_cast<stringop_alg *>(&default_algs->size[i].alg)
   1679           = input_ranges[i].alg;
   1680       *const_cast<int *>(&default_algs->size[i].noalign)
   1681           = input_ranges[i].noalign;
   1682     }
   1683 }
   1684 
   1685 
   1686 /* parse -mtune-ctrl= option. When DUMP is true,
   1688    print the features that are explicitly set.  */
   1689 
   1690 static void
   1691 parse_mtune_ctrl_str (struct gcc_options *opts, bool dump)
   1692 {
   1693   if (!opts->x_ix86_tune_ctrl_string)
   1694     return;
   1695 
   1696   char *next_feature_string = NULL;
   1697   char *curr_feature_string = xstrdup (opts->x_ix86_tune_ctrl_string);
   1698   char *orig = curr_feature_string;
   1699   int i;
   1700   do
   1701     {
   1702       bool clear = false;
   1703 
   1704       next_feature_string = strchr (curr_feature_string, ',');
   1705       if (next_feature_string)
   1706         *next_feature_string++ = '\0';
   1707       if (*curr_feature_string == '^')
   1708         {
   1709           curr_feature_string++;
   1710           clear = true;
   1711         }
   1712 
   1713       if (!strcmp (curr_feature_string, "use_gather"))
   1714 	{
   1715 	  ix86_tune_features[X86_TUNE_USE_GATHER_2PARTS] = !clear;
   1716 	  ix86_tune_features[X86_TUNE_USE_GATHER_4PARTS] = !clear;
   1717 	  ix86_tune_features[X86_TUNE_USE_GATHER_8PARTS] = !clear;
   1718 	  if (dump)
   1719 	    fprintf (stderr, "Explicitly %s features use_gather_2parts,"
   1720 		     " use_gather_4parts, use_gather_8parts\n",
   1721 		     clear ? "clear" : "set");
   1722 
   1723 	}
   1724       else if (!strcmp (curr_feature_string, "use_scatter"))
   1725 	{
   1726 	  ix86_tune_features[X86_TUNE_USE_SCATTER_2PARTS] = !clear;
   1727 	  ix86_tune_features[X86_TUNE_USE_SCATTER_4PARTS] = !clear;
   1728 	  ix86_tune_features[X86_TUNE_USE_SCATTER_8PARTS] = !clear;
   1729 	  if (dump)
   1730 	    fprintf (stderr, "Explicitly %s features use_scatter_2parts,"
   1731 		     " use_scatter_4parts, use_scatter_8parts\n",
   1732 		     clear ? "clear" : "set");
   1733 	}
   1734       else
   1735 	{
   1736 	  for (i = 0; i < X86_TUNE_LAST; i++)
   1737 	    {
   1738 	      if (!strcmp (curr_feature_string, ix86_tune_feature_names[i]))
   1739 		{
   1740 		  ix86_tune_features[i] = !clear;
   1741 		  if (dump)
   1742 		    fprintf (stderr, "Explicitly %s feature %s\n",
   1743 			     clear ? "clear" : "set", ix86_tune_feature_names[i]);
   1744 		  break;
   1745 		}
   1746 	    }
   1747 
   1748 	  if (i == X86_TUNE_LAST)
   1749 	    error ("unknown parameter to option %<-mtune-ctrl%>: %s",
   1750 		   clear ? curr_feature_string - 1 : curr_feature_string);
   1751 	}
   1752       curr_feature_string = next_feature_string;
   1753     }
   1754   while (curr_feature_string);
   1755   free (orig);
   1756 }
   1757 
   1758 /* Helper function to set ix86_tune_features. IX86_TUNE is the
   1759    processor type.  */
   1760 
   1761 static void
   1762 set_ix86_tune_features (struct gcc_options *opts,
   1763 			enum processor_type ix86_tune, bool dump)
   1764 {
   1765   unsigned HOST_WIDE_INT ix86_tune_mask = HOST_WIDE_INT_1U << ix86_tune;
   1766   int i;
   1767 
   1768   for (i = 0; i < X86_TUNE_LAST; ++i)
   1769     {
   1770       if (ix86_tune_no_default)
   1771         ix86_tune_features[i] = 0;
   1772       else
   1773 	ix86_tune_features[i]
   1774 	  = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
   1775     }
   1776 
   1777   if (dump)
   1778     {
   1779       fprintf (stderr, "List of x86 specific tuning parameter names:\n");
   1780       for (i = 0; i < X86_TUNE_LAST; i++)
   1781         fprintf (stderr, "%s : %s\n", ix86_tune_feature_names[i],
   1782                  ix86_tune_features[i] ? "on" : "off");
   1783     }
   1784 
   1785   parse_mtune_ctrl_str (opts, dump);
   1786 }
   1787 
   1788 
   1789 /* Default align_* from the processor table.  */
   1790 
   1791 static void
   1792 ix86_default_align (struct gcc_options *opts)
   1793 {
   1794   /* -falign-foo without argument: supply one.  */
   1795   if (opts->x_flag_align_loops && !opts->x_str_align_loops)
   1796     opts->x_str_align_loops = processor_cost_table[ix86_tune]->align_loop;
   1797   if (opts->x_flag_align_jumps && !opts->x_str_align_jumps)
   1798     opts->x_str_align_jumps = processor_cost_table[ix86_tune]->align_jump;
   1799   if (opts->x_flag_align_labels && !opts->x_str_align_labels)
   1800     opts->x_str_align_labels = processor_cost_table[ix86_tune]->align_label;
   1801   if (opts->x_flag_align_functions && !opts->x_str_align_functions)
   1802     opts->x_str_align_functions = processor_cost_table[ix86_tune]->align_func;
   1803 }
   1804 
   1805 #ifndef USE_IX86_FRAME_POINTER
   1806 #define USE_IX86_FRAME_POINTER 0
   1807 #endif
   1808 
   1809 /* (Re)compute option overrides affected by optimization levels in
   1810    target-specific ways.  */
   1811 
   1812 static void
   1813 ix86_recompute_optlev_based_flags (struct gcc_options *opts,
   1814 				   struct gcc_options *opts_set)
   1815 {
   1816   /* Set the default values for switches whose default depends on TARGET_64BIT
   1817      in case they weren't overwritten by command line options.  */
   1818   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
   1819     {
   1820       if (opts->x_optimize >= 1)
   1821 	SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer,
   1822 			     !USE_IX86_FRAME_POINTER);
   1823       if (opts->x_flag_asynchronous_unwind_tables
   1824 	  && TARGET_64BIT_MS_ABI)
   1825 	SET_OPTION_IF_UNSET (opts, opts_set, flag_unwind_tables, 1);
   1826       if (opts->x_flag_asynchronous_unwind_tables == 2)
   1827 	opts->x_flag_unwind_tables
   1828 	  = opts->x_flag_asynchronous_unwind_tables = 1;
   1829       if (opts->x_flag_pcc_struct_return == 2)
   1830 	opts->x_flag_pcc_struct_return = 0;
   1831     }
   1832   else
   1833     {
   1834       if (opts->x_optimize >= 1)
   1835 	  SET_OPTION_IF_UNSET (opts, opts_set, flag_omit_frame_pointer,
   1836 			       !(USE_IX86_FRAME_POINTER || opts->x_optimize_size));
   1837       if (opts->x_flag_asynchronous_unwind_tables == 2)
   1838 	opts->x_flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
   1839       if (opts->x_flag_pcc_struct_return == 2)
   1840 	{
   1841 	  /* Intel MCU psABI specifies that -freg-struct-return should
   1842 	     be on.  Instead of setting DEFAULT_PCC_STRUCT_RETURN to 0,
   1843 	     we check -miamcu so that -freg-struct-return is always
   1844 	     turned on if -miamcu is used.  */
   1845 	  if (TARGET_IAMCU_P (opts->x_target_flags))
   1846 	    opts->x_flag_pcc_struct_return = 0;
   1847 	  else
   1848 	    opts->x_flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
   1849 	}
   1850     }
   1851 }
   1852 
   1853 /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE hook.  */
   1854 
   1855 void
   1856 ix86_override_options_after_change (void)
   1857 {
   1858   ix86_default_align (&global_options);
   1859   ix86_recompute_optlev_based_flags (&global_options, &global_options_set);
   1860 }
   1861 
   1862 /* Clear stack slot assignments remembered from previous functions.
   1863    This is called from INIT_EXPANDERS once before RTL is emitted for each
   1864    function.  */
   1865 
   1866 static struct machine_function *
   1867 ix86_init_machine_status (void)
   1868 {
   1869   struct machine_function *f;
   1870 
   1871   f = ggc_cleared_alloc<machine_function> ();
   1872   f->call_abi = ix86_abi;
   1873   f->stack_frame_required = true;
   1874   f->silent_p = true;
   1875 
   1876   return f;
   1877 }
   1878 
   1879 /* Override various settings based on options.  If MAIN_ARGS_P, the
   1880    options are from the command line, otherwise they are from
   1881    attributes.  Return true if there's an error related to march
   1882    option.  */
   1883 
   1884 static bool
   1885 ix86_option_override_internal (bool main_args_p,
   1886 			       struct gcc_options *opts,
   1887 			       struct gcc_options *opts_set)
   1888 {
   1889   unsigned int i;
   1890   unsigned HOST_WIDE_INT ix86_arch_mask;
   1891   const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL);
   1892 
   1893   /* -mrecip options.  */
   1894   static struct
   1895     {
   1896       const char *string;           /* option name */
   1897       unsigned int mask;            /* mask bits to set */
   1898     }
   1899   const recip_options[] =
   1900     {
   1901       { "all",       RECIP_MASK_ALL },
   1902       { "none",      RECIP_MASK_NONE },
   1903       { "div",       RECIP_MASK_DIV },
   1904       { "sqrt",      RECIP_MASK_SQRT },
   1905       { "vec-div",   RECIP_MASK_VEC_DIV },
   1906       { "vec-sqrt",  RECIP_MASK_VEC_SQRT },
   1907     };
   1908 
   1909 
   1910   /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if
   1911      TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false.  */
   1912   if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
   1913     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
   1914 #ifdef TARGET_BI_ARCH
   1915   else
   1916     {
   1917 #if TARGET_BI_ARCH == 1
   1918       /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
   1919 	 is on and OPTION_MASK_ABI_X32 is off.  We turn off
   1920 	 OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
   1921 	 -mx32.  */
   1922       if (TARGET_X32_P (opts->x_ix86_isa_flags))
   1923 	opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
   1924 #else
   1925       /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
   1926 	 on and OPTION_MASK_ABI_64 is off.  We turn off
   1927 	 OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
   1928 	 -m64 or OPTION_MASK_CODE16 is turned on by -m16.  */
   1929       if (TARGET_LP64_P (opts->x_ix86_isa_flags)
   1930 	  || TARGET_16BIT_P (opts->x_ix86_isa_flags))
   1931 	opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
   1932 #endif
   1933       if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
   1934 	  && TARGET_IAMCU_P (opts->x_target_flags))
   1935 	sorry ("Intel MCU psABI isn%'t supported in %s mode",
   1936 	       TARGET_X32_P (opts->x_ix86_isa_flags) ? "x32" : "64-bit");
   1937     }
   1938 #endif
   1939 
   1940   if (TARGET_X32_P (opts->x_ix86_isa_flags))
   1941     {
   1942       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
   1943 	 OPTION_MASK_ABI_64 for TARGET_X32.  */
   1944       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
   1945       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
   1946     }
   1947   else if (TARGET_16BIT_P (opts->x_ix86_isa_flags))
   1948     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ISA_64BIT
   1949 				| OPTION_MASK_ABI_X32
   1950 				| OPTION_MASK_ABI_64);
   1951   else if (TARGET_LP64_P (opts->x_ix86_isa_flags))
   1952     {
   1953       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
   1954 	 OPTION_MASK_ABI_X32 for TARGET_LP64.  */
   1955       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
   1956       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
   1957     }
   1958 
   1959 #ifdef SUBTARGET_OVERRIDE_OPTIONS
   1960   SUBTARGET_OVERRIDE_OPTIONS;
   1961 #endif
   1962 
   1963 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
   1964   SUBSUBTARGET_OVERRIDE_OPTIONS;
   1965 #endif
   1966 
   1967 #ifdef HAVE_LD_BROKEN_PE_DWARF5
   1968   /* If the PE linker has broken DWARF 5 support, make
   1969      DWARF 4 the default.  */
   1970   if (TARGET_PECOFF)
   1971     SET_OPTION_IF_UNSET (opts, opts_set, dwarf_version, 4);
   1972 #endif
   1973 
   1974   /* -fPIC is the default for x86_64.  */
   1975   if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags))
   1976     opts->x_flag_pic = 2;
   1977 
   1978   /* Need to check -mtune=generic first.  */
   1979   if (opts->x_ix86_tune_string)
   1980     {
   1981       /* As special support for cross compilers we read -mtune=native
   1982 	     as -mtune=generic.  With native compilers we won't see the
   1983 	     -mtune=native, as it was changed by the driver.  */
   1984       if (!strcmp (opts->x_ix86_tune_string, "native"))
   1985 	opts->x_ix86_tune_string = "generic";
   1986       else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
   1987         warning (OPT_Wdeprecated,
   1988 		 main_args_p
   1989 		 ? G_("%<-mtune=x86-64%> is deprecated; use %<-mtune=k8%> "
   1990 		      "or %<-mtune=generic%> instead as appropriate")
   1991 		 : G_("%<target(\"tune=x86-64\")%> is deprecated; use "
   1992 		      "%<target(\"tune=k8\")%> or %<target(\"tune=generic\")%>"
   1993 		      " instead as appropriate"));
   1994     }
   1995   else
   1996     {
   1997       if (opts->x_ix86_arch_string)
   1998 	opts->x_ix86_tune_string = opts->x_ix86_arch_string;
   1999       if (!opts->x_ix86_tune_string)
   2000 	{
   2001 	  opts->x_ix86_tune_string = processor_names[TARGET_CPU_DEFAULT];
   2002 	  ix86_tune_defaulted = 1;
   2003 	}
   2004 
   2005       /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
   2006 	 or defaulted.  We need to use a sensible tune option.  */
   2007       if (startswith (opts->x_ix86_tune_string, "x86-64")
   2008 	  && (opts->x_ix86_tune_string[6] == '\0'
   2009 	      || (!strcmp (opts->x_ix86_tune_string + 6, "-v2")
   2010 		  || !strcmp (opts->x_ix86_tune_string + 6, "-v3")
   2011 		  || !strcmp (opts->x_ix86_tune_string + 6, "-v4"))))
   2012 	opts->x_ix86_tune_string = "generic";
   2013     }
   2014 
   2015   if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
   2016       && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2017     {
   2018       /* rep; movq isn't available in 32-bit code.  */
   2019       error ("%<-mstringop-strategy=rep_8byte%> not supported for 32-bit code");
   2020       opts->x_ix86_stringop_alg = no_stringop;
   2021     }
   2022 
   2023   if (TARGET_UINTR && !TARGET_64BIT)
   2024     error ("%<-muintr%> not supported for 32-bit code");
   2025 
   2026   if (!opts->x_ix86_arch_string)
   2027     opts->x_ix86_arch_string
   2028       = TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2029 	? "x86-64" : SUBTARGET32_DEFAULT_CPU;
   2030   else
   2031     ix86_arch_specified = 1;
   2032 
   2033   if (opts_set->x_ix86_pmode)
   2034     {
   2035       if ((TARGET_LP64_P (opts->x_ix86_isa_flags)
   2036 	   && opts->x_ix86_pmode == PMODE_SI)
   2037 	  || (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2038 	       && opts->x_ix86_pmode == PMODE_DI))
   2039 	error ("address mode %qs not supported in the %s bit mode",
   2040 	       TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "short" : "long",
   2041 	       TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "64" : "32");
   2042     }
   2043   else
   2044     opts->x_ix86_pmode = TARGET_LP64_P (opts->x_ix86_isa_flags)
   2045 			 ? PMODE_DI : PMODE_SI;
   2046 
   2047   SET_OPTION_IF_UNSET (opts, opts_set, ix86_abi, DEFAULT_ABI);
   2048 
   2049   if (opts->x_ix86_abi == MS_ABI && TARGET_X32_P (opts->x_ix86_isa_flags))
   2050     error ("%<-mabi=ms%> not supported with X32 ABI");
   2051   gcc_assert (opts->x_ix86_abi == SYSV_ABI || opts->x_ix86_abi == MS_ABI);
   2052 
   2053   const char *abi_name = opts->x_ix86_abi == MS_ABI ? "ms" : "sysv";
   2054   if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
   2055       && opts->x_ix86_abi != DEFAULT_ABI)
   2056     error ("%<-mabi=%s%> not supported with %<-fsanitize=address%>", abi_name);
   2057   if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
   2058       && opts->x_ix86_abi != DEFAULT_ABI)
   2059     error ("%<-mabi=%s%> not supported with %<-fsanitize=kernel-address%>",
   2060 	   abi_name);
   2061   if ((opts->x_flag_sanitize & SANITIZE_THREAD)
   2062       && opts->x_ix86_abi != DEFAULT_ABI)
   2063     error ("%<-mabi=%s%> not supported with %<-fsanitize=thread%>", abi_name);
   2064 
   2065   /* For targets using ms ABI enable ms-extensions, if not
   2066      explicit turned off.  For non-ms ABI we turn off this
   2067      option.  */
   2068   SET_OPTION_IF_UNSET (opts, opts_set, flag_ms_extensions,
   2069 		       (MS_ABI == DEFAULT_ABI));
   2070 
   2071   if (opts_set->x_ix86_cmodel)
   2072     {
   2073       switch (opts->x_ix86_cmodel)
   2074 	{
   2075 	case CM_SMALL:
   2076 	case CM_SMALL_PIC:
   2077 	  if (opts->x_flag_pic)
   2078 	    opts->x_ix86_cmodel = CM_SMALL_PIC;
   2079 	  if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2080 	    error ("code model %qs not supported in the %s bit mode",
   2081 		   "small", "32");
   2082 	  break;
   2083 
   2084 	case CM_MEDIUM:
   2085 	case CM_MEDIUM_PIC:
   2086 	  if (opts->x_flag_pic)
   2087 	    opts->x_ix86_cmodel = CM_MEDIUM_PIC;
   2088 	  if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2089 	    error ("code model %qs not supported in the %s bit mode",
   2090 		   "medium", "32");
   2091 	  else if (TARGET_X32_P (opts->x_ix86_isa_flags))
   2092 	    error ("code model %qs not supported in x32 mode",
   2093 		   "medium");
   2094 	  break;
   2095 
   2096 	case CM_LARGE:
   2097 	case CM_LARGE_PIC:
   2098 	  if (opts->x_flag_pic)
   2099 	    opts->x_ix86_cmodel = CM_LARGE_PIC;
   2100 	  if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2101 	    error ("code model %qs not supported in the %s bit mode",
   2102 		   "large", "32");
   2103 	  else if (TARGET_X32_P (opts->x_ix86_isa_flags))
   2104 	    error ("code model %qs not supported in x32 mode",
   2105 		   "large");
   2106 	  break;
   2107 
   2108 	case CM_32:
   2109 	  if (opts->x_flag_pic)
   2110 	    error ("code model %s does not support PIC mode", "32");
   2111 	  if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2112 	    error ("code model %qs not supported in the %s bit mode",
   2113 		   "32", "64");
   2114 	  break;
   2115 
   2116 	case CM_KERNEL:
   2117 	  if (opts->x_flag_pic)
   2118 	    {
   2119 	      error ("code model %s does not support PIC mode", "kernel");
   2120 	      opts->x_ix86_cmodel = CM_32;
   2121 	    }
   2122 	  if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2123 	    error ("code model %qs not supported in the %s bit mode",
   2124 		   "kernel", "32");
   2125 	  break;
   2126 
   2127 	default:
   2128 	  gcc_unreachable ();
   2129 	}
   2130     }
   2131   else
   2132     {
   2133       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
   2134 	 use of rip-relative addressing.  This eliminates fixups that
   2135 	 would otherwise be needed if this object is to be placed in a
   2136 	 DLL, and is essentially just as efficient as direct addressing.  */
   2137       if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2138 	  && (TARGET_RDOS || TARGET_PECOFF))
   2139 	opts->x_ix86_cmodel = CM_MEDIUM_PIC, opts->x_flag_pic = 1;
   2140       else if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2141 	opts->x_ix86_cmodel = opts->x_flag_pic ? CM_SMALL_PIC : CM_SMALL;
   2142       else
   2143 	opts->x_ix86_cmodel = CM_32;
   2144     }
   2145   if (TARGET_MACHO && opts->x_ix86_asm_dialect == ASM_INTEL)
   2146     {
   2147       error ("%<-masm=intel%> not supported in this configuration");
   2148       opts->x_ix86_asm_dialect = ASM_ATT;
   2149     }
   2150   if ((TARGET_64BIT_P (opts->x_ix86_isa_flags) != 0)
   2151       != ((opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
   2152     sorry ("%i-bit mode not compiled in",
   2153 	   (opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
   2154 
   2155   /* Last processor_alias_table must point to "generic" entry.  */
   2156   gcc_checking_assert (strcmp (processor_alias_table[pta_size - 1].name,
   2157 			       "generic") == 0);
   2158   for (i = 0; i < pta_size; i++)
   2159     if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name))
   2160       {
   2161 	if (!strcmp (opts->x_ix86_arch_string, "generic"))
   2162 	  {
   2163 	    error (main_args_p
   2164 		   ? G_("%<generic%> CPU can be used only for %<-mtune=%> "
   2165 			"switch")
   2166 		   : G_("%<generic%> CPU can be used only for "
   2167 			"%<target(\"tune=\")%> attribute"));
   2168 	    return false;
   2169 	  }
   2170 	else if (!strcmp (opts->x_ix86_arch_string, "intel"))
   2171 	  {
   2172 	    error (main_args_p
   2173 		   ? G_("%<intel%> CPU can be used only for %<-mtune=%> "
   2174 			"switch")
   2175 		   : G_("%<intel%> CPU can be used only for "
   2176 			"%<target(\"tune=\")%> attribute"));
   2177 	    return false;
   2178 	  }
   2179 
   2180 	if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2181 	    && !((processor_alias_table[i].flags & PTA_64BIT) != 0))
   2182 	  {
   2183 	    error ("CPU you selected does not support x86-64 "
   2184 		   "instruction set");
   2185 	    return false;
   2186 	  }
   2187 
   2188 	ix86_schedule = processor_alias_table[i].schedule;
   2189 	ix86_arch = processor_alias_table[i].processor;
   2190 
   2191 	/* Default cpu tuning to the architecture, unless the table
   2192 	   entry requests not to do this.  Used by the x86-64 psABI
   2193 	   micro-architecture levels.  */
   2194 	if ((processor_alias_table[i].flags & PTA_NO_TUNE) == 0)
   2195 	  ix86_tune = ix86_arch;
   2196 	else
   2197 	  ix86_tune = PROCESSOR_GENERIC;
   2198 
   2199 	/* Enable PTA flags that are enabled by default by a -march option.  */
   2200 #define TARGET_EXPLICIT_NO_SAHF_P(opts) (false)
   2201 #define SET_TARGET_NO_SAHF(opts) {}
   2202 #define TARGET_EXPLICIT_PREFETCH_SSE_P(opts) (false)
   2203 #define SET_TARGET_PREFETCH_SSE(opts) {}
   2204 #define TARGET_EXPLICIT_NO_TUNE_P(opts) (false)
   2205 #define SET_TARGET_NO_TUNE(opts) {}
   2206 #define TARGET_EXPLICIT_NO_80387_P(opts) (false)
   2207 #define SET_TARGET_NO_80387(opts) {}
   2208 
   2209 #define DEF_PTA(NAME) \
   2210 	if (((processor_alias_table[i].flags & PTA_ ## NAME) != 0) \
   2211 	    && PTA_ ## NAME != PTA_64BIT \
   2212 	    && (TARGET_64BIT || PTA_ ## NAME != PTA_UINTR) \
   2213 	    && !TARGET_EXPLICIT_ ## NAME ## _P (opts)) \
   2214 	  SET_TARGET_ ## NAME (opts);
   2215 #include "i386-isa.def"
   2216 #undef DEF_PTA
   2217 
   2218 
   2219        if (!(TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2220 	     && ((processor_alias_table[i].flags & PTA_NO_SAHF) != 0))
   2221 	   && !TARGET_EXPLICIT_SAHF_P (opts))
   2222 	    SET_TARGET_SAHF (opts);
   2223 
   2224 	if (((processor_alias_table[i].flags & PTA_ABM) != 0)
   2225 	    && !TARGET_EXPLICIT_ABM_P (opts))
   2226 	  {
   2227 	    if (!TARGET_EXPLICIT_LZCNT_P (opts))
   2228 	      SET_TARGET_LZCNT (opts);
   2229 	    if (!TARGET_EXPLICIT_POPCNT_P (opts))
   2230 	      SET_TARGET_POPCNT (opts);
   2231 	  }
   2232 
   2233 	if ((processor_alias_table[i].flags
   2234 	   & (PTA_PREFETCH_SSE | PTA_SSE)) != 0)
   2235 	  ix86_prefetch_sse = true;
   2236 
   2237 	/* Don't enable x87 instructions if only general registers are
   2238 	   allowed by target("general-regs-only") function attribute or
   2239 	   -mgeneral-regs-only.  */
   2240 	if (!(opts->x_ix86_target_flags & OPTION_MASK_GENERAL_REGS_ONLY)
   2241 	    && !(opts_set->x_target_flags & MASK_80387))
   2242 	  {
   2243 	    if (((processor_alias_table[i].flags & PTA_NO_80387) != 0))
   2244 	      opts->x_target_flags &= ~MASK_80387;
   2245 	    else
   2246 	      opts->x_target_flags |= MASK_80387;
   2247 	  }
   2248 	break;
   2249       }
   2250 
   2251   if (i == pta_size)
   2252     {
   2253       error (main_args_p
   2254 	     ? G_("bad value %qs for %<-march=%> switch")
   2255 	     : G_("bad value %qs for %<target(\"arch=\")%> attribute"),
   2256 	     opts->x_ix86_arch_string);
   2257 
   2258       auto_vec <const char *> candidates;
   2259       for (i = 0; i < pta_size; i++)
   2260 	if (strcmp (processor_alias_table[i].name, "generic")
   2261 	    && strcmp (processor_alias_table[i].name, "intel")
   2262 	    && (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2263 		|| ((processor_alias_table[i].flags & PTA_64BIT) != 0)))
   2264 	  candidates.safe_push (processor_alias_table[i].name);
   2265 
   2266 #ifdef HAVE_LOCAL_CPU_DETECT
   2267       /* Add also "native" as possible value.  */
   2268       candidates.safe_push ("native");
   2269 #endif
   2270 
   2271       char *s;
   2272       const char *hint
   2273 	= candidates_list_and_hint (opts->x_ix86_arch_string, s, candidates);
   2274       if (hint)
   2275 	inform (input_location,
   2276 		main_args_p
   2277 		? G_("valid arguments to %<-march=%> switch are: "
   2278 		     "%s; did you mean %qs?")
   2279 		: G_("valid arguments to %<target(\"arch=\")%> attribute are: "
   2280 		     "%s; did you mean %qs?"), s, hint);
   2281       else
   2282 	inform (input_location,
   2283 		main_args_p
   2284 		? G_("valid arguments to %<-march=%> switch are: %s")
   2285 		: G_("valid arguments to %<target(\"arch=\")%> attribute "
   2286 		     "are: %s"), s);
   2287       XDELETEVEC (s);
   2288     }
   2289 
   2290   ix86_arch_mask = HOST_WIDE_INT_1U << ix86_arch;
   2291   for (i = 0; i < X86_ARCH_LAST; ++i)
   2292     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
   2293 
   2294   for (i = 0; i < pta_size; i++)
   2295     if (! strcmp (opts->x_ix86_tune_string, processor_alias_table[i].name)
   2296 	&& (processor_alias_table[i].flags & PTA_NO_TUNE) == 0)
   2297       {
   2298 	ix86_schedule = processor_alias_table[i].schedule;
   2299 	ix86_tune = processor_alias_table[i].processor;
   2300 	if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2301 	  {
   2302 	    if (!((processor_alias_table[i].flags & PTA_64BIT) != 0))
   2303 	      {
   2304 		if (ix86_tune_defaulted)
   2305 		  {
   2306 		    opts->x_ix86_tune_string = "x86-64";
   2307 		    for (i = 0; i < pta_size; i++)
   2308 		      if (! strcmp (opts->x_ix86_tune_string,
   2309 				    processor_alias_table[i].name))
   2310 			break;
   2311 		    ix86_schedule = processor_alias_table[i].schedule;
   2312 		    ix86_tune = processor_alias_table[i].processor;
   2313 		  }
   2314 		else
   2315 		  error ("CPU you selected does not support x86-64 "
   2316 			 "instruction set");
   2317 	      }
   2318 	  }
   2319 	/* Intel CPUs have always interpreted SSE prefetch instructions as
   2320 	   NOPs; so, we can enable SSE prefetch instructions even when
   2321 	   -mtune (rather than -march) points us to a processor that has them.
   2322 	   However, the VIA C3 gives a SIGILL, so we only do that for i686 and
   2323 	   higher processors.  */
   2324 	if (TARGET_CMOV
   2325 	    && ((processor_alias_table[i].flags
   2326 	      & (PTA_PREFETCH_SSE | PTA_SSE)) != 0))
   2327 	  ix86_prefetch_sse = true;
   2328 	break;
   2329       }
   2330 
   2331   if (ix86_tune_specified && i == pta_size)
   2332     {
   2333       error (main_args_p
   2334 	     ? G_("bad value %qs for %<-mtune=%> switch")
   2335 	     : G_("bad value %qs for %<target(\"tune=\")%> attribute"),
   2336 	     opts->x_ix86_tune_string);
   2337 
   2338       auto_vec <const char *> candidates;
   2339       for (i = 0; i < pta_size; i++)
   2340 	if ((!TARGET_64BIT_P (opts->x_ix86_isa_flags)
   2341 	     || ((processor_alias_table[i].flags & PTA_64BIT) != 0))
   2342 	    && (processor_alias_table[i].flags & PTA_NO_TUNE) == 0)
   2343 	  candidates.safe_push (processor_alias_table[i].name);
   2344 
   2345 #ifdef HAVE_LOCAL_CPU_DETECT
   2346       /* Add also "native" as possible value.  */
   2347       candidates.safe_push ("native");
   2348 #endif
   2349 
   2350       char *s;
   2351       const char *hint
   2352 	= candidates_list_and_hint (opts->x_ix86_tune_string, s, candidates);
   2353       if (hint)
   2354 	inform (input_location,
   2355 		main_args_p
   2356 		? G_("valid arguments to %<-mtune=%> switch are: "
   2357 		     "%s; did you mean %qs?")
   2358 		: G_("valid arguments to %<target(\"tune=\")%> attribute are: "
   2359 		     "%s; did you mean %qs?"), s, hint);
   2360       else
   2361 	inform (input_location,
   2362 		main_args_p
   2363 		? G_("valid arguments to %<-mtune=%> switch are: %s")
   2364 		: G_("valid arguments to %<target(\"tune=\")%> attribute "
   2365 		     "are: %s"), s);
   2366       XDELETEVEC (s);
   2367     }
   2368 
   2369   set_ix86_tune_features (opts, ix86_tune, opts->x_ix86_dump_tunes);
   2370 
   2371   ix86_recompute_optlev_based_flags (opts, opts_set);
   2372 
   2373   ix86_tune_cost = processor_cost_table[ix86_tune];
   2374   /* TODO: ix86_cost should be chosen at instruction or function granuality
   2375      so for cold code we use size_cost even in !optimize_size compilation.  */
   2376   if (opts->x_optimize_size)
   2377     ix86_cost = &ix86_size_cost;
   2378   else
   2379     ix86_cost = ix86_tune_cost;
   2380 
   2381   /* Arrange to set up i386_stack_locals for all functions.  */
   2382   init_machine_status = ix86_init_machine_status;
   2383 
   2384   /* Validate -mregparm= value.  */
   2385   if (opts_set->x_ix86_regparm)
   2386     {
   2387       if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2388 	warning (0, "%<-mregparm%> is ignored in 64-bit mode");
   2389       else if (TARGET_IAMCU_P (opts->x_target_flags))
   2390 	warning (0, "%<-mregparm%> is ignored for Intel MCU psABI");
   2391       if (opts->x_ix86_regparm > REGPARM_MAX)
   2392 	{
   2393 	  error ("%<-mregparm=%d%> is not between 0 and %d",
   2394 		 opts->x_ix86_regparm, REGPARM_MAX);
   2395 	  opts->x_ix86_regparm = 0;
   2396 	}
   2397     }
   2398   if (TARGET_IAMCU_P (opts->x_target_flags)
   2399       || TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2400     opts->x_ix86_regparm = REGPARM_MAX;
   2401 
   2402   /* Default align_* from the processor table.  */
   2403   ix86_default_align (opts);
   2404 
   2405   /* Provide default for -mbranch-cost= value.  */
   2406   SET_OPTION_IF_UNSET (opts, opts_set, ix86_branch_cost,
   2407 		       ix86_tune_cost->branch_cost);
   2408 
   2409   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2410     {
   2411       opts->x_target_flags
   2412 	|= TARGET_SUBTARGET64_DEFAULT & ~opts_set->x_target_flags;
   2413 
   2414       if (!ix86_arch_specified)
   2415 	opts->x_ix86_isa_flags
   2416 	  |= TARGET_SUBTARGET64_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit;
   2417 
   2418       if (!TARGET_128BIT_LONG_DOUBLE_P (opts->x_target_flags))
   2419 	error ("%<-m96bit-long-double%> is not compatible with this target");
   2420 
   2421       if (TARGET_RTD_P (opts->x_target_flags))
   2422 	warning (0,
   2423 		 main_args_p
   2424 		 ? G_("%<-mrtd%> is ignored in 64bit mode")
   2425 		 : G_("%<target(\"rtd\")%> is ignored in 64bit mode"));
   2426     }
   2427   else
   2428     {
   2429       opts->x_target_flags
   2430 	|= TARGET_SUBTARGET32_DEFAULT & ~opts_set->x_target_flags;
   2431 
   2432       if (!ix86_arch_specified)
   2433         opts->x_ix86_isa_flags
   2434 	  |= TARGET_SUBTARGET32_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit;
   2435 
   2436       /* i386 ABI does not specify red zone.  It still makes sense to use it
   2437          when programmer takes care to stack from being destroyed.  */
   2438       if (!(opts_set->x_target_flags & MASK_NO_RED_ZONE))
   2439         opts->x_target_flags |= MASK_NO_RED_ZONE;
   2440     }
   2441 
   2442   /* Keep nonleaf frame pointers.  */
   2443   if (opts->x_flag_omit_frame_pointer)
   2444     opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
   2445   else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags))
   2446     opts->x_flag_omit_frame_pointer = 1;
   2447 
   2448   /* If we're doing fast math, we don't care about comparison order
   2449      wrt NaNs.  This lets us use a shorter comparison sequence.  */
   2450   if (opts->x_flag_finite_math_only)
   2451     opts->x_target_flags &= ~MASK_IEEE_FP;
   2452 
   2453   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
   2454      since the insns won't need emulation.  */
   2455   if (ix86_tune_features [X86_TUNE_ALWAYS_FANCY_MATH_387])
   2456     opts->x_target_flags &= ~MASK_NO_FANCY_MATH_387;
   2457 
   2458   /* Likewise, if the target doesn't have a 387, or we've specified
   2459      software floating point, don't use 387 inline intrinsics.  */
   2460   if (!TARGET_80387_P (opts->x_target_flags))
   2461     opts->x_target_flags |= MASK_NO_FANCY_MATH_387;
   2462 
   2463   /* Turn on MMX builtins for -msse.  */
   2464   if (TARGET_SSE_P (opts->x_ix86_isa_flags))
   2465     opts->x_ix86_isa_flags
   2466       |= OPTION_MASK_ISA_MMX & ~opts->x_ix86_isa_flags_explicit;
   2467 
   2468   /* Enable SSE prefetch.  */
   2469   if (TARGET_SSE_P (opts->x_ix86_isa_flags)
   2470       || (TARGET_PRFCHW_P (opts->x_ix86_isa_flags)
   2471 	  && !TARGET_3DNOW_P (opts->x_ix86_isa_flags))
   2472       || TARGET_PREFETCHWT1_P (opts->x_ix86_isa_flags))
   2473     ix86_prefetch_sse = true;
   2474 
   2475   /* Enable mwait/monitor instructions for -msse3.  */
   2476   if (TARGET_SSE3_P (opts->x_ix86_isa_flags))
   2477     opts->x_ix86_isa_flags2
   2478       |= OPTION_MASK_ISA2_MWAIT & ~opts->x_ix86_isa_flags2_explicit;
   2479 
   2480   /* Enable popcnt instruction for -msse4.2 or -mabm.  */
   2481   if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags)
   2482       || TARGET_ABM_P (opts->x_ix86_isa_flags))
   2483     opts->x_ix86_isa_flags
   2484       |= OPTION_MASK_ISA_POPCNT & ~opts->x_ix86_isa_flags_explicit;
   2485 
   2486   /* Enable crc32 instruction for -msse4.2.  */
   2487   if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags))
   2488     opts->x_ix86_isa_flags
   2489       |= OPTION_MASK_ISA_CRC32 & ~opts->x_ix86_isa_flags_explicit;
   2490 
   2491   /* Enable lzcnt instruction for -mabm.  */
   2492   if (TARGET_ABM_P(opts->x_ix86_isa_flags))
   2493     opts->x_ix86_isa_flags
   2494       |= OPTION_MASK_ISA_LZCNT & ~opts->x_ix86_isa_flags_explicit;
   2495 
   2496   /* Disable BMI, BMI2 and TBM instructions for -m16.  */
   2497   if (TARGET_16BIT_P(opts->x_ix86_isa_flags))
   2498     opts->x_ix86_isa_flags
   2499       &= ~((OPTION_MASK_ISA_BMI | OPTION_MASK_ISA_BMI2 | OPTION_MASK_ISA_TBM)
   2500 	   & ~opts->x_ix86_isa_flags_explicit);
   2501 
   2502   /* Validate -mpreferred-stack-boundary= value or default it to
   2503      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
   2504   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
   2505   if (opts_set->x_ix86_preferred_stack_boundary_arg)
   2506     {
   2507       int min = TARGET_64BIT_P (opts->x_ix86_isa_flags)? 3 : 2;
   2508       int max = TARGET_SEH ? 4 : 12;
   2509 
   2510       if (opts->x_ix86_preferred_stack_boundary_arg < min
   2511 	  || opts->x_ix86_preferred_stack_boundary_arg > max)
   2512 	{
   2513 	  if (min == max)
   2514 	    error ("%<-mpreferred-stack-boundary%> is not supported "
   2515 		   "for this target");
   2516 	  else
   2517 	    error ("%<-mpreferred-stack-boundary=%d%> is not between %d and %d",
   2518 		   opts->x_ix86_preferred_stack_boundary_arg, min, max);
   2519 	}
   2520       else
   2521 	ix86_preferred_stack_boundary
   2522 	  = (1 << opts->x_ix86_preferred_stack_boundary_arg) * BITS_PER_UNIT;
   2523     }
   2524 
   2525   /* Set the default value for -mstackrealign.  */
   2526   SET_OPTION_IF_UNSET (opts, opts_set, ix86_force_align_arg_pointer,
   2527 		       STACK_REALIGN_DEFAULT);
   2528 
   2529   ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
   2530 
   2531   /* Validate -mincoming-stack-boundary= value or default it to
   2532      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
   2533   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
   2534   if (opts_set->x_ix86_incoming_stack_boundary_arg)
   2535     {
   2536       int min = TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 3 : 2;
   2537 
   2538       if (opts->x_ix86_incoming_stack_boundary_arg < min
   2539 	  || opts->x_ix86_incoming_stack_boundary_arg > 12)
   2540 	error ("%<-mincoming-stack-boundary=%d%> is not between %d and 12",
   2541 	       opts->x_ix86_incoming_stack_boundary_arg, min);
   2542       else
   2543 	{
   2544 	  ix86_user_incoming_stack_boundary
   2545 	    = (1 << opts->x_ix86_incoming_stack_boundary_arg) * BITS_PER_UNIT;
   2546 	  ix86_incoming_stack_boundary
   2547 	    = ix86_user_incoming_stack_boundary;
   2548 	}
   2549     }
   2550 
   2551 #ifndef NO_PROFILE_COUNTERS
   2552   if (flag_nop_mcount)
   2553     error ("%<-mnop-mcount%> is not compatible with this target");
   2554 #endif
   2555   if (flag_nop_mcount && flag_pic)
   2556     error ("%<-mnop-mcount%> is not implemented for %<-fPIC%>");
   2557 
   2558   /* Accept -msseregparm only if at least SSE support is enabled.  */
   2559   if (TARGET_SSEREGPARM_P (opts->x_target_flags)
   2560       && ! TARGET_SSE_P (opts->x_ix86_isa_flags))
   2561     error (main_args_p
   2562 	   ? G_("%<-msseregparm%> used without SSE enabled")
   2563 	   : G_("%<target(\"sseregparm\")%> used without SSE enabled"));
   2564 
   2565   if (opts_set->x_ix86_fpmath)
   2566     {
   2567       if (opts->x_ix86_fpmath & FPMATH_SSE)
   2568 	{
   2569 	  if (!TARGET_SSE_P (opts->x_ix86_isa_flags))
   2570 	    {
   2571 	      if (TARGET_80387_P (opts->x_target_flags))
   2572 		{
   2573 		  warning (0, "SSE instruction set disabled, using 387 arithmetics");
   2574 		  opts->x_ix86_fpmath = FPMATH_387;
   2575 		}
   2576 	    }
   2577 	  else if ((opts->x_ix86_fpmath & FPMATH_387)
   2578 		   && !TARGET_80387_P (opts->x_target_flags))
   2579 	    {
   2580 	      warning (0, "387 instruction set disabled, using SSE arithmetics");
   2581 	      opts->x_ix86_fpmath = FPMATH_SSE;
   2582 	    }
   2583 	}
   2584     }
   2585   /* For all chips supporting SSE2, -mfpmath=sse performs better than
   2586      fpmath=387.  The second is however default at many targets since the
   2587      extra 80bit precision of temporaries is considered to be part of ABI.
   2588      Overwrite the default at least for -ffast-math.
   2589      TODO: -mfpmath=both seems to produce same performing code with bit
   2590      smaller binaries.  It is however not clear if register allocation is
   2591      ready for this setting.
   2592      Also -mfpmath=387 is overall a lot more compact (bout 4-5%) than SSE
   2593      codegen.  We may switch to 387 with -ffast-math for size optimized
   2594      functions. */
   2595   else if (fast_math_flags_set_p (&global_options)
   2596 	   && TARGET_SSE2_P (opts->x_ix86_isa_flags))
   2597     opts->x_ix86_fpmath = FPMATH_SSE;
   2598   else
   2599     opts->x_ix86_fpmath = TARGET_FPMATH_DEFAULT_P (opts->x_ix86_isa_flags);
   2600 
   2601   /* Use external vectorized library in vectorizing intrinsics.  */
   2602   if (opts_set->x_ix86_veclibabi_type)
   2603     switch (opts->x_ix86_veclibabi_type)
   2604       {
   2605       case ix86_veclibabi_type_svml:
   2606 	ix86_veclib_handler = &ix86_veclibabi_svml;
   2607 	break;
   2608 
   2609       case ix86_veclibabi_type_acml:
   2610 	ix86_veclib_handler = &ix86_veclibabi_acml;
   2611 	break;
   2612 
   2613       default:
   2614 	gcc_unreachable ();
   2615       }
   2616 
   2617   if (ix86_tune_features [X86_TUNE_ACCUMULATE_OUTGOING_ARGS]
   2618       && !(opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
   2619     opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
   2620 
   2621   /* If stack probes are required, the space used for large function
   2622      arguments on the stack must also be probed, so enable
   2623      -maccumulate-outgoing-args so this happens in the prologue.  */
   2624   if (TARGET_STACK_PROBE_P (opts->x_target_flags)
   2625       && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
   2626     {
   2627       if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)
   2628 	warning (0,
   2629 		 main_args_p
   2630 		 ? G_("stack probing requires %<-maccumulate-outgoing-args%> "
   2631 		      "for correctness")
   2632 		 : G_("stack probing requires "
   2633 		      "%<target(\"accumulate-outgoing-args\")%> for "
   2634 		      "correctness"));
   2635       opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
   2636     }
   2637 
   2638   /* Stack realignment without -maccumulate-outgoing-args requires %ebp,
   2639      so enable -maccumulate-outgoing-args when %ebp is fixed.  */
   2640   if (fixed_regs[BP_REG]
   2641       && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
   2642     {
   2643       if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)
   2644 	warning (0,
   2645 		 main_args_p
   2646 		 ? G_("fixed ebp register requires "
   2647 		      "%<-maccumulate-outgoing-args%>")
   2648 		 : G_("fixed ebp register requires "
   2649 		      "%<target(\"accumulate-outgoing-args\")%>"));
   2650       opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
   2651     }
   2652 
   2653   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
   2654   {
   2655     char *p;
   2656     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
   2657     p = strchr (internal_label_prefix, 'X');
   2658     internal_label_prefix_len = p - internal_label_prefix;
   2659     *p = '\0';
   2660   }
   2661 
   2662   /* When scheduling description is not available, disable scheduler pass
   2663      so it won't slow down the compilation and make x87 code slower.  */
   2664   if (!TARGET_SCHEDULE)
   2665     opts->x_flag_schedule_insns_after_reload = opts->x_flag_schedule_insns = 0;
   2666 
   2667   SET_OPTION_IF_UNSET (opts, opts_set, param_simultaneous_prefetches,
   2668 		       ix86_tune_cost->simultaneous_prefetches);
   2669   SET_OPTION_IF_UNSET (opts, opts_set, param_l1_cache_line_size,
   2670 		       ix86_tune_cost->prefetch_block);
   2671   SET_OPTION_IF_UNSET (opts, opts_set, param_l1_cache_size,
   2672 		       ix86_tune_cost->l1_cache_size);
   2673   SET_OPTION_IF_UNSET (opts, opts_set, param_l2_cache_size,
   2674 		       ix86_tune_cost->l2_cache_size);
   2675 
   2676   /* 64B is the accepted value for these for all x86.  */
   2677   SET_OPTION_IF_UNSET (&global_options, &global_options_set,
   2678 		       param_destruct_interfere_size, 64);
   2679   SET_OPTION_IF_UNSET (&global_options, &global_options_set,
   2680 		       param_construct_interfere_size, 64);
   2681 
   2682   /* Enable sw prefetching at -O3 for CPUS that prefetching is helpful.  */
   2683   if (opts->x_flag_prefetch_loop_arrays < 0
   2684       && HAVE_prefetch
   2685       && (opts->x_optimize >= 3 || opts->x_flag_profile_use)
   2686       && !opts->x_optimize_size
   2687       && TARGET_SOFTWARE_PREFETCHING_BENEFICIAL)
   2688     opts->x_flag_prefetch_loop_arrays = 1;
   2689 
   2690   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
   2691      can be opts->x_optimized to ap = __builtin_next_arg (0).  */
   2692   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && !opts->x_flag_split_stack)
   2693     targetm.expand_builtin_va_start = NULL;
   2694 
   2695 #ifdef USE_IX86_CLD
   2696   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
   2697   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
   2698     opts->x_target_flags |= MASK_CLD & ~opts_set->x_target_flags;
   2699 #endif
   2700 
   2701   /* Set the default value for -mfentry.  */
   2702   if (!opts_set->x_flag_fentry)
   2703     opts->x_flag_fentry = TARGET_SEH;
   2704   else
   2705     {
   2706       if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && opts->x_flag_pic
   2707 	  && opts->x_flag_fentry)
   2708 	sorry ("%<-mfentry%> isn%'t supported for 32-bit in combination "
   2709 	       "with %<-fpic%>");
   2710       else if (TARGET_SEH && !opts->x_flag_fentry)
   2711 	sorry ("%<-mno-fentry%> isn%'t compatible with SEH");
   2712     }
   2713 
   2714   if (TARGET_SEH && TARGET_CALL_MS2SYSV_XLOGUES)
   2715     sorry ("%<-mcall-ms2sysv-xlogues%> isn%'t currently supported with SEH");
   2716 
   2717   if (!(opts_set->x_target_flags & MASK_VZEROUPPER)
   2718       && TARGET_EMIT_VZEROUPPER
   2719       && flag_expensive_optimizations
   2720       && !optimize_size)
   2721     opts->x_target_flags |= MASK_VZEROUPPER;
   2722   if (!(opts_set->x_target_flags & MASK_STV))
   2723     opts->x_target_flags |= MASK_STV;
   2724   /* Disable STV if -mpreferred-stack-boundary={2,3} or
   2725      -mincoming-stack-boundary={2,3} or -mstackrealign - the needed
   2726      stack realignment will be extra cost the pass doesn't take into
   2727      account and the pass can't realign the stack.  */
   2728   if (ix86_preferred_stack_boundary < 128
   2729       || ix86_incoming_stack_boundary < 128
   2730       || opts->x_ix86_force_align_arg_pointer)
   2731     opts->x_target_flags &= ~MASK_STV;
   2732   if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL]
   2733       && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_LOAD))
   2734     opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_LOAD;
   2735   else if (!main_args_p
   2736 	   && ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL])
   2737     opts->x_target_flags &= ~MASK_AVX256_SPLIT_UNALIGNED_LOAD;
   2738 
   2739   if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL]
   2740       && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_STORE))
   2741     opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_STORE;
   2742   else if (!main_args_p
   2743 	   && ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL])
   2744     opts->x_target_flags &= ~MASK_AVX256_SPLIT_UNALIGNED_STORE;
   2745 
   2746   /* Enable 128-bit AVX instruction generation
   2747      for the auto-vectorizer.  */
   2748   if (ix86_tune_features[X86_TUNE_AVX128_OPTIMAL]
   2749       && (opts_set->x_prefer_vector_width_type == PVW_NONE))
   2750     opts->x_prefer_vector_width_type = PVW_AVX128;
   2751 
   2752   /* Use 256-bit AVX instruction generation
   2753      in the auto-vectorizer.  */
   2754   if (ix86_tune_features[X86_TUNE_AVX256_OPTIMAL]
   2755       && (opts_set->x_prefer_vector_width_type == PVW_NONE))
   2756     opts->x_prefer_vector_width_type = PVW_AVX256;
   2757 
   2758   if (opts_set->x_ix86_move_max == PVW_NONE)
   2759     {
   2760       /* Set the maximum number of bits can be moved from memory to
   2761 	 memory efficiently.  */
   2762       if (ix86_tune_features[X86_TUNE_AVX512_MOVE_BY_PIECES])
   2763 	opts->x_ix86_move_max = PVW_AVX512;
   2764       else if (ix86_tune_features[X86_TUNE_AVX256_MOVE_BY_PIECES])
   2765 	opts->x_ix86_move_max = PVW_AVX256;
   2766       else
   2767 	{
   2768 	  opts->x_ix86_move_max = opts->x_prefer_vector_width_type;
   2769 	  if (opts_set->x_ix86_move_max == PVW_NONE)
   2770 	    {
   2771 	      if (TARGET_AVX512F_P (opts->x_ix86_isa_flags))
   2772 		opts->x_ix86_move_max = PVW_AVX512;
   2773 	      /* Align with vectorizer to avoid potential STLF issue.  */
   2774 	      else if (TARGET_AVX_P (opts->x_ix86_isa_flags))
   2775 		opts->x_ix86_move_max = PVW_AVX256;
   2776 	      else
   2777 		opts->x_ix86_move_max = PVW_AVX128;
   2778 	    }
   2779 	}
   2780     }
   2781 
   2782   if (opts_set->x_ix86_store_max == PVW_NONE)
   2783     {
   2784       /* Set the maximum number of bits can be stored to memory
   2785 	 efficiently.  */
   2786       if (ix86_tune_features[X86_TUNE_AVX512_STORE_BY_PIECES])
   2787 	opts->x_ix86_store_max = PVW_AVX512;
   2788       else if (ix86_tune_features[X86_TUNE_AVX256_STORE_BY_PIECES])
   2789 	opts->x_ix86_store_max = PVW_AVX256;
   2790       else
   2791 	{
   2792 	  opts->x_ix86_store_max = opts->x_prefer_vector_width_type;
   2793 	  if (opts_set->x_ix86_store_max == PVW_NONE)
   2794 	    {
   2795 	      if (TARGET_AVX512F_P (opts->x_ix86_isa_flags))
   2796 		opts->x_ix86_store_max = PVW_AVX512;
   2797 	      /* Align with vectorizer to avoid potential STLF issue.  */
   2798 	      else if (TARGET_AVX_P (opts->x_ix86_isa_flags))
   2799 		opts->x_ix86_store_max = PVW_AVX256;
   2800 	      else
   2801 		opts->x_ix86_store_max = PVW_AVX128;
   2802 	    }
   2803 	}
   2804     }
   2805 
   2806   if (opts->x_ix86_recip_name)
   2807     {
   2808       char *p = ASTRDUP (opts->x_ix86_recip_name);
   2809       char *q;
   2810       unsigned int mask;
   2811       bool invert;
   2812 
   2813       while ((q = strtok (p, ",")) != NULL)
   2814 	{
   2815 	  p = NULL;
   2816 	  if (*q == '!')
   2817 	    {
   2818 	      invert = true;
   2819 	      q++;
   2820 	    }
   2821 	  else
   2822 	    invert = false;
   2823 
   2824 	  if (!strcmp (q, "default"))
   2825 	    mask = RECIP_MASK_ALL;
   2826 	  else
   2827 	    {
   2828 	      for (i = 0; i < ARRAY_SIZE (recip_options); i++)
   2829 		if (!strcmp (q, recip_options[i].string))
   2830 		  {
   2831 		    mask = recip_options[i].mask;
   2832 		    break;
   2833 		  }
   2834 
   2835 	      if (i == ARRAY_SIZE (recip_options))
   2836 		{
   2837 		  error ("unknown option for %<-mrecip=%s%>", q);
   2838 		  invert = false;
   2839 		  mask = RECIP_MASK_NONE;
   2840 		}
   2841 	    }
   2842 
   2843 	  opts->x_recip_mask_explicit |= mask;
   2844 	  if (invert)
   2845 	    opts->x_recip_mask &= ~mask;
   2846 	  else
   2847 	    opts->x_recip_mask |= mask;
   2848 	}
   2849     }
   2850 
   2851   if (TARGET_RECIP_P (opts->x_target_flags))
   2852     opts->x_recip_mask |= RECIP_MASK_ALL & ~opts->x_recip_mask_explicit;
   2853   else if (opts_set->x_target_flags & MASK_RECIP)
   2854     opts->x_recip_mask &= ~(RECIP_MASK_ALL & ~opts->x_recip_mask_explicit);
   2855 
   2856   /* Default long double to 64-bit for 32-bit Bionic and to __float128
   2857      for 64-bit Bionic.  Also default long double to 64-bit for Intel
   2858      MCU psABI.  */
   2859   if ((TARGET_HAS_BIONIC || TARGET_IAMCU)
   2860       && !(opts_set->x_target_flags
   2861 	   & (MASK_LONG_DOUBLE_64 | MASK_LONG_DOUBLE_128)))
   2862     opts->x_target_flags |= (TARGET_64BIT
   2863 			     ? MASK_LONG_DOUBLE_128
   2864 			     : MASK_LONG_DOUBLE_64);
   2865 
   2866   /* Only one of them can be active.  */
   2867   gcc_assert ((opts->x_target_flags & MASK_LONG_DOUBLE_64) == 0
   2868 	      || (opts->x_target_flags & MASK_LONG_DOUBLE_128) == 0);
   2869 
   2870   /* Handle stack protector */
   2871   if (!opts_set->x_ix86_stack_protector_guard)
   2872     {
   2873 #ifdef TARGET_THREAD_SSP_OFFSET
   2874       if (!TARGET_HAS_BIONIC)
   2875 	opts->x_ix86_stack_protector_guard = SSP_TLS;
   2876       else
   2877 #endif
   2878 	opts->x_ix86_stack_protector_guard = SSP_GLOBAL;
   2879     }
   2880 
   2881   if (opts_set->x_ix86_stack_protector_guard_offset_str)
   2882     {
   2883       char *endp;
   2884       const char *str = opts->x_ix86_stack_protector_guard_offset_str;
   2885 
   2886       errno = 0;
   2887       int64_t offset;
   2888 
   2889 #if defined(INT64_T_IS_LONG)
   2890       offset = strtol (str, &endp, 0);
   2891 #else
   2892       offset = strtoll (str, &endp, 0);
   2893 #endif
   2894 
   2895       if (!*str || *endp || errno)
   2896 	error ("%qs is not a valid number "
   2897 	       "in %<-mstack-protector-guard-offset=%>", str);
   2898 
   2899       if (!IN_RANGE (offset, HOST_WIDE_INT_C (-0x80000000),
   2900 		     HOST_WIDE_INT_C (0x7fffffff)))
   2901 	error ("%qs is not a valid offset "
   2902 	       "in %<-mstack-protector-guard-offset=%>", str);
   2903 
   2904       opts->x_ix86_stack_protector_guard_offset = offset;
   2905     }
   2906 #ifdef TARGET_THREAD_SSP_OFFSET
   2907   else
   2908     opts->x_ix86_stack_protector_guard_offset = TARGET_THREAD_SSP_OFFSET;
   2909 #endif
   2910 
   2911   if (opts_set->x_ix86_stack_protector_guard_reg_str)
   2912     {
   2913       const char *str = opts->x_ix86_stack_protector_guard_reg_str;
   2914       addr_space_t seg = ADDR_SPACE_GENERIC;
   2915 
   2916       /* Discard optional register prefix.  */
   2917       if (str[0] == '%')
   2918 	str++;
   2919 
   2920       if (strlen (str) == 2 && str[1] == 's')
   2921 	{
   2922 	  if (str[0] == 'f')
   2923 	    seg = ADDR_SPACE_SEG_FS;
   2924 	  else if (str[0] == 'g')
   2925 	    seg = ADDR_SPACE_SEG_GS;
   2926 	}
   2927 
   2928       if (seg == ADDR_SPACE_GENERIC)
   2929 	error ("%qs is not a valid base register "
   2930 	       "in %<-mstack-protector-guard-reg=%>",
   2931 	       opts->x_ix86_stack_protector_guard_reg_str);
   2932 
   2933       opts->x_ix86_stack_protector_guard_reg = seg;
   2934     }
   2935   else
   2936     {
   2937       opts->x_ix86_stack_protector_guard_reg = DEFAULT_TLS_SEG_REG;
   2938 
   2939       /* The kernel uses a different segment register for performance
   2940 	 reasons; a system call would not have to trash the userspace
   2941 	 segment register, which would be expensive.  */
   2942       if (opts->x_ix86_cmodel == CM_KERNEL)
   2943 	opts->x_ix86_stack_protector_guard_reg = ADDR_SPACE_SEG_GS;
   2944     }
   2945 
   2946   /* Handle -mmemcpy-strategy= and -mmemset-strategy=  */
   2947   if (opts->x_ix86_tune_memcpy_strategy)
   2948     {
   2949       char *str = xstrdup (opts->x_ix86_tune_memcpy_strategy);
   2950       ix86_parse_stringop_strategy_string (str, false);
   2951       free (str);
   2952     }
   2953 
   2954   if (opts->x_ix86_tune_memset_strategy)
   2955     {
   2956       char *str = xstrdup (opts->x_ix86_tune_memset_strategy);
   2957       ix86_parse_stringop_strategy_string (str, true);
   2958       free (str);
   2959     }
   2960 
   2961   /* Save the initial options in case the user does function specific
   2962      options.  */
   2963   if (main_args_p)
   2964     {
   2965       opts->x_ix86_excess_precision
   2966 	= opts->x_flag_excess_precision;
   2967       opts->x_ix86_unsafe_math_optimizations
   2968 	= opts->x_flag_unsafe_math_optimizations;
   2969       target_option_default_node = target_option_current_node
   2970         = build_target_option_node (opts, opts_set);
   2971     }
   2972 
   2973   if (opts->x_flag_cf_protection != CF_NONE)
   2974     {
   2975       if ((opts->x_flag_cf_protection & CF_BRANCH) == CF_BRANCH
   2976 	  && !TARGET_64BIT && !TARGET_CMOV)
   2977 	error ("%<-fcf-protection%> is not compatible with this target");
   2978 
   2979       opts->x_flag_cf_protection
   2980       = (cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
   2981     }
   2982 
   2983   if (ix86_tune_features [X86_TUNE_AVOID_256FMA_CHAINS])
   2984     SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 512);
   2985   else if (ix86_tune_features [X86_TUNE_AVOID_256FMA_CHAINS])
   2986     SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 256);
   2987   else if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS])
   2988     SET_OPTION_IF_UNSET (opts, opts_set, param_avoid_fma_max_bits, 128);
   2989 
   2990   /* PR86952: jump table usage with retpolines is slow.
   2991      The PR provides some numbers about the slowness.  */
   2992   if (ix86_indirect_branch != indirect_branch_keep)
   2993     SET_OPTION_IF_UNSET (opts, opts_set, flag_jump_tables, 0);
   2994 
   2995   SET_OPTION_IF_UNSET (opts, opts_set, param_ira_consider_dup_in_all_alts, 0);
   2996 
   2997   /* Fully masking the main or the epilogue vectorized loop is not
   2998      profitable generally so leave it disabled until we get more
   2999      fine grained control & costing.  */
   3000   SET_OPTION_IF_UNSET (opts, opts_set, param_vect_partial_vector_usage, 0);
   3001 
   3002   return true;
   3003 }
   3004 
   3005 /* Implement the TARGET_OPTION_OVERRIDE hook.  */
   3006 
   3007 void
   3008 ix86_option_override (void)
   3009 {
   3010   ix86_option_override_internal (true, &global_options, &global_options_set);
   3011 }
   3012 
   3013 /* Remember the last target of ix86_set_current_function.  */
   3014 static GTY(()) tree ix86_previous_fndecl;
   3015 
   3016 /* Set targets globals to the default (or current #pragma GCC target
   3017    if active).  Invalidate ix86_previous_fndecl cache.  */
   3018 
   3019 void
   3020 ix86_reset_previous_fndecl (void)
   3021 {
   3022   tree new_tree = target_option_current_node;
   3023   cl_target_option_restore (&global_options, &global_options_set,
   3024 			    TREE_TARGET_OPTION (new_tree));
   3025   if (TREE_TARGET_GLOBALS (new_tree))
   3026     restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
   3027   else if (new_tree == target_option_default_node)
   3028     restore_target_globals (&default_target_globals);
   3029   else
   3030     TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
   3031   ix86_previous_fndecl = NULL_TREE;
   3032 }
   3033 
   3034 /* Add target attribute to SIMD clone NODE if needed.  */
   3035 
   3036 void
   3037 ix86_simd_clone_adjust (struct cgraph_node *node)
   3038 {
   3039   const char *str = NULL;
   3040 
   3041   /* Attributes need to be adjusted for definitions, not declarations.  */
   3042   if (!node->definition)
   3043     return;
   3044 
   3045   gcc_assert (node->decl == cfun->decl);
   3046   switch (node->simdclone->vecsize_mangle)
   3047     {
   3048     case 'b':
   3049       if (!TARGET_SSE2)
   3050 	str = "sse2";
   3051       break;
   3052     case 'c':
   3053       if (TARGET_PREFER_AVX128)
   3054 	{
   3055 	  if (!TARGET_AVX)
   3056 	    str = "avx,prefer-vector-width=256";
   3057 	  else
   3058 	    str = "prefer-vector-width=256";
   3059 	}
   3060       else if (!TARGET_AVX)
   3061 	str = "avx";
   3062       break;
   3063     case 'd':
   3064       if (TARGET_PREFER_AVX128)
   3065 	{
   3066 	  if (!TARGET_AVX2)
   3067 	    str = "avx2,prefer-vector-width=256";
   3068 	  else
   3069 	    str = "prefer-vector-width=256";
   3070 	}
   3071       else if (!TARGET_AVX2)
   3072 	str = "avx2";
   3073       break;
   3074     case 'e':
   3075       if (TARGET_PREFER_AVX256)
   3076 	{
   3077 	  if (!TARGET_AVX512F)
   3078 	    str = "avx512f,prefer-vector-width=512";
   3079 	  else
   3080 	    str = "prefer-vector-width=512";
   3081 	}
   3082       else if (!TARGET_AVX512F)
   3083 	str = "avx512f";
   3084       break;
   3085     default:
   3086       gcc_unreachable ();
   3087     }
   3088   if (str == NULL)
   3089     return;
   3090   push_cfun (NULL);
   3091   tree args = build_tree_list (NULL_TREE, build_string (strlen (str), str));
   3092   bool ok = ix86_valid_target_attribute_p (node->decl, NULL, args, 0);
   3093   gcc_assert (ok);
   3094   pop_cfun ();
   3095   ix86_reset_previous_fndecl ();
   3096   ix86_set_current_function (node->decl);
   3097 }
   3098 
   3099 
   3100 
   3101 /* Set the func_type field from the function FNDECL.  */
   3102 
   3103 static void
   3104 ix86_set_func_type (tree fndecl)
   3105 {
   3106   if (cfun->machine->func_type == TYPE_UNKNOWN)
   3107     {
   3108       if (lookup_attribute ("interrupt",
   3109 			    TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
   3110 	{
   3111 	  if (ix86_function_naked (fndecl))
   3112 	    error_at (DECL_SOURCE_LOCATION (fndecl),
   3113 		      "interrupt and naked attributes are not compatible");
   3114 
   3115 	  int nargs = 0;
   3116 	  for (tree arg = DECL_ARGUMENTS (fndecl);
   3117 	       arg;
   3118 	       arg = TREE_CHAIN (arg))
   3119 	    nargs++;
   3120 	  cfun->machine->no_caller_saved_registers = true;
   3121 	  cfun->machine->func_type
   3122 	    = nargs == 2 ? TYPE_EXCEPTION : TYPE_INTERRUPT;
   3123 
   3124 	  ix86_optimize_mode_switching[X86_DIRFLAG] = 1;
   3125 
   3126 	  /* Only dwarf2out.cc can handle -WORD(AP) as a pointer argument.  */
   3127 	  if (write_symbols != NO_DEBUG && write_symbols != DWARF2_DEBUG)
   3128 	    sorry ("only DWARF debug format is supported for interrupt "
   3129 		   "service routine");
   3130 	}
   3131       else
   3132 	{
   3133 	  cfun->machine->func_type = TYPE_NORMAL;
   3134 	  if (lookup_attribute ("no_caller_saved_registers",
   3135 				TYPE_ATTRIBUTES (TREE_TYPE (fndecl))))
   3136 	    cfun->machine->no_caller_saved_registers = true;
   3137 	}
   3138     }
   3139 }
   3140 
   3141 /* Set the indirect_branch_type field from the function FNDECL.  */
   3142 
   3143 static void
   3144 ix86_set_indirect_branch_type (tree fndecl)
   3145 {
   3146   if (cfun->machine->indirect_branch_type == indirect_branch_unset)
   3147     {
   3148       tree attr = lookup_attribute ("indirect_branch",
   3149 				    DECL_ATTRIBUTES (fndecl));
   3150       if (attr != NULL)
   3151 	{
   3152 	  tree args = TREE_VALUE (attr);
   3153 	  if (args == NULL)
   3154 	    gcc_unreachable ();
   3155 	  tree cst = TREE_VALUE (args);
   3156 	  if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0)
   3157 	    cfun->machine->indirect_branch_type = indirect_branch_keep;
   3158 	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0)
   3159 	    cfun->machine->indirect_branch_type = indirect_branch_thunk;
   3160 	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0)
   3161 	    cfun->machine->indirect_branch_type = indirect_branch_thunk_inline;
   3162 	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0)
   3163 	    cfun->machine->indirect_branch_type = indirect_branch_thunk_extern;
   3164 	  else
   3165 	    gcc_unreachable ();
   3166 	}
   3167       else
   3168 	cfun->machine->indirect_branch_type = ix86_indirect_branch;
   3169 
   3170       /* -mcmodel=large is not compatible with -mindirect-branch=thunk
   3171 	 nor -mindirect-branch=thunk-extern.  */
   3172       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
   3173 	  && ((cfun->machine->indirect_branch_type
   3174 	       == indirect_branch_thunk_extern)
   3175 	      || (cfun->machine->indirect_branch_type
   3176 		  == indirect_branch_thunk)))
   3177 	error ("%<-mindirect-branch=%s%> and %<-mcmodel=large%> are not "
   3178 	       "compatible",
   3179 	       ((cfun->machine->indirect_branch_type
   3180 		 == indirect_branch_thunk_extern)
   3181 		? "thunk-extern" : "thunk"));
   3182 
   3183       if (cfun->machine->indirect_branch_type != indirect_branch_keep
   3184 	  && (cfun->machine->indirect_branch_type
   3185 	      != indirect_branch_thunk_extern)
   3186 	  && (flag_cf_protection & CF_RETURN))
   3187 	error ("%<-mindirect-branch%> and %<-fcf-protection%> are not "
   3188 	       "compatible");
   3189     }
   3190 
   3191   if (cfun->machine->function_return_type == indirect_branch_unset)
   3192     {
   3193       tree attr = lookup_attribute ("function_return",
   3194 				    DECL_ATTRIBUTES (fndecl));
   3195       if (attr != NULL)
   3196 	{
   3197 	  tree args = TREE_VALUE (attr);
   3198 	  if (args == NULL)
   3199 	    gcc_unreachable ();
   3200 	  tree cst = TREE_VALUE (args);
   3201 	  if (strcmp (TREE_STRING_POINTER (cst), "keep") == 0)
   3202 	    cfun->machine->function_return_type = indirect_branch_keep;
   3203 	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk") == 0)
   3204 	    cfun->machine->function_return_type = indirect_branch_thunk;
   3205 	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk-inline") == 0)
   3206 	    cfun->machine->function_return_type = indirect_branch_thunk_inline;
   3207 	  else if (strcmp (TREE_STRING_POINTER (cst), "thunk-extern") == 0)
   3208 	    cfun->machine->function_return_type = indirect_branch_thunk_extern;
   3209 	  else
   3210 	    gcc_unreachable ();
   3211 	}
   3212       else
   3213 	cfun->machine->function_return_type = ix86_function_return;
   3214 
   3215       /* -mcmodel=large is not compatible with -mfunction-return=thunk
   3216 	 nor -mfunction-return=thunk-extern.  */
   3217       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
   3218 	  && ((cfun->machine->function_return_type
   3219 	       == indirect_branch_thunk_extern)
   3220 	      || (cfun->machine->function_return_type
   3221 		  == indirect_branch_thunk)))
   3222 	error ("%<-mfunction-return=%s%> and %<-mcmodel=large%> are not "
   3223 	       "compatible",
   3224 	       ((cfun->machine->function_return_type
   3225 		 == indirect_branch_thunk_extern)
   3226 		? "thunk-extern" : "thunk"));
   3227 
   3228       if (cfun->machine->function_return_type != indirect_branch_keep
   3229 	  && (cfun->machine->function_return_type
   3230 	      != indirect_branch_thunk_extern)
   3231 	  && (flag_cf_protection & CF_RETURN))
   3232 	error ("%<-mfunction-return%> and %<-fcf-protection%> are not "
   3233 	       "compatible");
   3234     }
   3235 }
   3236 
   3237 /* Establish appropriate back-end context for processing the function
   3238    FNDECL.  The argument might be NULL to indicate processing at top
   3239    level, outside of any function scope.  */
   3240 void
   3241 ix86_set_current_function (tree fndecl)
   3242 {
   3243   /* Only change the context if the function changes.  This hook is called
   3244      several times in the course of compiling a function, and we don't want to
   3245      slow things down too much or call target_reinit when it isn't safe.  */
   3246   if (fndecl == ix86_previous_fndecl)
   3247     {
   3248       /* There may be 2 function bodies for the same function FNDECL,
   3249 	 one is extern inline and one isn't.  Call ix86_set_func_type
   3250 	 to set the func_type field.  */
   3251       if (fndecl != NULL_TREE)
   3252 	{
   3253 	  ix86_set_func_type (fndecl);
   3254 	  ix86_set_indirect_branch_type (fndecl);
   3255 	}
   3256       return;
   3257     }
   3258 
   3259   tree old_tree;
   3260   if (ix86_previous_fndecl == NULL_TREE)
   3261     old_tree = target_option_current_node;
   3262   else if (DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl))
   3263     old_tree = DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl);
   3264   else
   3265     old_tree = target_option_default_node;
   3266 
   3267   if (fndecl == NULL_TREE)
   3268     {
   3269       if (old_tree != target_option_current_node)
   3270 	ix86_reset_previous_fndecl ();
   3271       return;
   3272     }
   3273 
   3274   ix86_set_func_type (fndecl);
   3275   ix86_set_indirect_branch_type (fndecl);
   3276 
   3277   tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
   3278   if (new_tree == NULL_TREE)
   3279     new_tree = target_option_default_node;
   3280 
   3281   bool fp_flag_change
   3282     = (flag_unsafe_math_optimizations
   3283        != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations
   3284        || (flag_excess_precision
   3285 	   != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision));
   3286   if (old_tree != new_tree || fp_flag_change)
   3287     {
   3288       cl_target_option_restore (&global_options, &global_options_set,
   3289 				TREE_TARGET_OPTION (new_tree));
   3290       if (fp_flag_change)
   3291 	{
   3292 	  ix86_excess_precision = flag_excess_precision;
   3293 	  ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations;
   3294 	  DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree
   3295 	    = build_target_option_node (&global_options, &global_options_set);
   3296 	}
   3297       if (TREE_TARGET_GLOBALS (new_tree))
   3298 	restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
   3299       else if (new_tree == target_option_default_node)
   3300 	restore_target_globals (&default_target_globals);
   3301       else
   3302 	TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts ();
   3303     }
   3304   ix86_previous_fndecl = fndecl;
   3305 
   3306   static bool prev_no_caller_saved_registers;
   3307 
   3308   /* 64-bit MS and SYSV ABI have different set of call used registers.
   3309      Avoid expensive re-initialization of init_regs each time we switch
   3310      function context.  */
   3311   if (TARGET_64BIT
   3312       && (call_used_or_fixed_reg_p (SI_REG)
   3313 	  == (cfun->machine->call_abi == MS_ABI)))
   3314     reinit_regs ();
   3315   /* Need to re-initialize init_regs if caller-saved registers are
   3316      changed.  */
   3317   else if (prev_no_caller_saved_registers
   3318 	   != cfun->machine->no_caller_saved_registers)
   3319     reinit_regs ();
   3320 
   3321   if (cfun->machine->func_type != TYPE_NORMAL
   3322       || cfun->machine->no_caller_saved_registers)
   3323     {
   3324       /* Don't allow SSE, MMX nor x87 instructions since they
   3325 	 may change processor state.  */
   3326       const char *isa;
   3327       if (TARGET_SSE)
   3328 	isa = "SSE";
   3329       else if (TARGET_MMX)
   3330 	isa = "MMX/3Dnow";
   3331       else if (TARGET_80387)
   3332 	isa = "80387";
   3333       else
   3334 	isa = NULL;
   3335       if (isa != NULL)
   3336 	{
   3337 	  if (cfun->machine->func_type != TYPE_NORMAL)
   3338 	    sorry (cfun->machine->func_type == TYPE_EXCEPTION
   3339 		   ? G_("%s instructions aren%'t allowed in an"
   3340 			" exception service routine")
   3341 		   : G_("%s instructions aren%'t allowed in an"
   3342 			" interrupt service routine"),
   3343 		   isa);
   3344 	  else
   3345 	    sorry ("%s instructions aren%'t allowed in a function with "
   3346 		   "the %<no_caller_saved_registers%> attribute", isa);
   3347 	  /* Don't issue the same error twice.  */
   3348 	  cfun->machine->func_type = TYPE_NORMAL;
   3349 	  cfun->machine->no_caller_saved_registers = false;
   3350 	}
   3351     }
   3352 
   3353   prev_no_caller_saved_registers
   3354     = cfun->machine->no_caller_saved_registers;
   3355 }
   3356 
   3357 /* Implement the TARGET_OFFLOAD_OPTIONS hook.  */
   3358 char *
   3359 ix86_offload_options (void)
   3360 {
   3361   if (TARGET_LP64)
   3362     return xstrdup ("-foffload-abi=lp64");
   3363   return xstrdup ("-foffload-abi=ilp32");
   3364 }
   3365 
   3366 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
   3367    and "sseregparm" calling convention attributes;
   3368    arguments as in struct attribute_spec.handler.  */
   3369 
   3370 static tree
   3371 ix86_handle_cconv_attribute (tree *node, tree name, tree args, int,
   3372 			     bool *no_add_attrs)
   3373 {
   3374   if (TREE_CODE (*node) != FUNCTION_TYPE
   3375       && TREE_CODE (*node) != METHOD_TYPE
   3376       && TREE_CODE (*node) != FIELD_DECL
   3377       && TREE_CODE (*node) != TYPE_DECL)
   3378     {
   3379       warning (OPT_Wattributes, "%qE attribute only applies to functions",
   3380 	       name);
   3381       *no_add_attrs = true;
   3382       return NULL_TREE;
   3383     }
   3384 
   3385   /* Can combine regparm with all attributes but fastcall, and thiscall.  */
   3386   if (is_attribute_p ("regparm", name))
   3387     {
   3388       tree cst;
   3389 
   3390       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
   3391         {
   3392 	  error ("fastcall and regparm attributes are not compatible");
   3393 	}
   3394 
   3395       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
   3396 	{
   3397 	  error ("regparam and thiscall attributes are not compatible");
   3398 	}
   3399 
   3400       cst = TREE_VALUE (args);
   3401       if (TREE_CODE (cst) != INTEGER_CST)
   3402 	{
   3403 	  warning (OPT_Wattributes,
   3404 		   "%qE attribute requires an integer constant argument",
   3405 		   name);
   3406 	  *no_add_attrs = true;
   3407 	}
   3408       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
   3409 	{
   3410 	  warning (OPT_Wattributes, "argument to %qE attribute larger than %d",
   3411 		   name, REGPARM_MAX);
   3412 	  *no_add_attrs = true;
   3413 	}
   3414 
   3415       return NULL_TREE;
   3416     }
   3417 
   3418   if (TARGET_64BIT)
   3419     {
   3420       /* Do not warn when emulating the MS ABI.  */
   3421       if ((TREE_CODE (*node) != FUNCTION_TYPE
   3422 	   && TREE_CODE (*node) != METHOD_TYPE)
   3423 	  || ix86_function_type_abi (*node) != MS_ABI)
   3424 	warning (OPT_Wattributes, "%qE attribute ignored",
   3425 	         name);
   3426       *no_add_attrs = true;
   3427       return NULL_TREE;
   3428     }
   3429 
   3430   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
   3431   if (is_attribute_p ("fastcall", name))
   3432     {
   3433       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
   3434         {
   3435 	  error ("fastcall and cdecl attributes are not compatible");
   3436 	}
   3437       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
   3438         {
   3439 	  error ("fastcall and stdcall attributes are not compatible");
   3440 	}
   3441       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
   3442         {
   3443 	  error ("fastcall and regparm attributes are not compatible");
   3444 	}
   3445       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
   3446 	{
   3447 	  error ("fastcall and thiscall attributes are not compatible");
   3448 	}
   3449     }
   3450 
   3451   /* Can combine stdcall with fastcall (redundant), regparm and
   3452      sseregparm.  */
   3453   else if (is_attribute_p ("stdcall", name))
   3454     {
   3455       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
   3456         {
   3457 	  error ("stdcall and cdecl attributes are not compatible");
   3458 	}
   3459       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
   3460         {
   3461 	  error ("stdcall and fastcall attributes are not compatible");
   3462 	}
   3463       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
   3464 	{
   3465 	  error ("stdcall and thiscall attributes are not compatible");
   3466 	}
   3467     }
   3468 
   3469   /* Can combine cdecl with regparm and sseregparm.  */
   3470   else if (is_attribute_p ("cdecl", name))
   3471     {
   3472       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
   3473         {
   3474 	  error ("stdcall and cdecl attributes are not compatible");
   3475 	}
   3476       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
   3477         {
   3478 	  error ("fastcall and cdecl attributes are not compatible");
   3479 	}
   3480       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
   3481 	{
   3482 	  error ("cdecl and thiscall attributes are not compatible");
   3483 	}
   3484     }
   3485   else if (is_attribute_p ("thiscall", name))
   3486     {
   3487       if (TREE_CODE (*node) != METHOD_TYPE && pedantic)
   3488 	warning (OPT_Wattributes, "%qE attribute is used for non-class method",
   3489 	         name);
   3490       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
   3491 	{
   3492 	  error ("stdcall and thiscall attributes are not compatible");
   3493 	}
   3494       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
   3495 	{
   3496 	  error ("fastcall and thiscall attributes are not compatible");
   3497 	}
   3498       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
   3499 	{
   3500 	  error ("cdecl and thiscall attributes are not compatible");
   3501 	}
   3502     }
   3503 
   3504   /* Can combine sseregparm with all attributes.  */
   3505 
   3506   return NULL_TREE;
   3507 }
   3508 
   3509 #ifndef CHECK_STACK_LIMIT
   3510 #define CHECK_STACK_LIMIT (-1)
   3511 #endif
   3512 
   3513 /* The transactional memory builtins are implicitly regparm or fastcall
   3514    depending on the ABI.  Override the generic do-nothing attribute that
   3515    these builtins were declared with, and replace it with one of the two
   3516    attributes that we expect elsewhere.  */
   3517 
   3518 static tree
   3519 ix86_handle_tm_regparm_attribute (tree *node, tree, tree,
   3520 				  int flags, bool *no_add_attrs)
   3521 {
   3522   tree alt;
   3523 
   3524   /* In no case do we want to add the placeholder attribute.  */
   3525   *no_add_attrs = true;
   3526 
   3527   /* The 64-bit ABI is unchanged for transactional memory.  */
   3528   if (TARGET_64BIT)
   3529     return NULL_TREE;
   3530 
   3531   /* ??? Is there a better way to validate 32-bit windows?  We have
   3532      cfun->machine->call_abi, but that seems to be set only for 64-bit.  */
   3533   if (CHECK_STACK_LIMIT > 0)
   3534     alt = tree_cons (get_identifier ("fastcall"), NULL, NULL);
   3535   else
   3536     {
   3537       alt = tree_cons (NULL, build_int_cst (NULL, 2), NULL);
   3538       alt = tree_cons (get_identifier ("regparm"), alt, NULL);
   3539     }
   3540   decl_attributes (node, alt, flags);
   3541 
   3542   return NULL_TREE;
   3543 }
   3544 
   3545 /* Handle a "force_align_arg_pointer" attribute.  */
   3546 
   3547 static tree
   3548 ix86_handle_force_align_arg_pointer_attribute (tree *node, tree name,
   3549 					       tree, int, bool *no_add_attrs)
   3550 {
   3551   if (TREE_CODE (*node) != FUNCTION_TYPE
   3552       && TREE_CODE (*node) != METHOD_TYPE
   3553       && TREE_CODE (*node) != FIELD_DECL
   3554       && TREE_CODE (*node) != TYPE_DECL)
   3555     {
   3556       warning (OPT_Wattributes, "%qE attribute only applies to functions",
   3557 	       name);
   3558       *no_add_attrs = true;
   3559     }
   3560 
   3561   return NULL_TREE;
   3562 }
   3563 
   3564 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
   3565    struct attribute_spec.handler.  */
   3566 
   3567 static tree
   3568 ix86_handle_struct_attribute (tree *node, tree name, tree, int,
   3569 			      bool *no_add_attrs)
   3570 {
   3571   tree *type = NULL;
   3572   if (DECL_P (*node))
   3573     {
   3574       if (TREE_CODE (*node) == TYPE_DECL)
   3575 	type = &TREE_TYPE (*node);
   3576     }
   3577   else
   3578     type = node;
   3579 
   3580   if (!(type && RECORD_OR_UNION_TYPE_P (*type)))
   3581     {
   3582       warning (OPT_Wattributes, "%qE attribute ignored",
   3583 	       name);
   3584       *no_add_attrs = true;
   3585     }
   3586 
   3587   else if ((is_attribute_p ("ms_struct", name)
   3588 	    && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
   3589 	   || ((is_attribute_p ("gcc_struct", name)
   3590 		&& lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
   3591     {
   3592       warning (OPT_Wattributes, "%qE incompatible attribute ignored",
   3593                name);
   3594       *no_add_attrs = true;
   3595     }
   3596 
   3597   return NULL_TREE;
   3598 }
   3599 
   3600 /* Handle a "callee_pop_aggregate_return" attribute; arguments as
   3601    in struct attribute_spec handler.  */
   3602 
   3603 static tree
   3604 ix86_handle_callee_pop_aggregate_return (tree *node, tree name, tree args, int,
   3605 					 bool *no_add_attrs)
   3606 {
   3607   if (TREE_CODE (*node) != FUNCTION_TYPE
   3608       && TREE_CODE (*node) != METHOD_TYPE
   3609       && TREE_CODE (*node) != FIELD_DECL
   3610       && TREE_CODE (*node) != TYPE_DECL)
   3611     {
   3612       warning (OPT_Wattributes, "%qE attribute only applies to functions",
   3613 	       name);
   3614       *no_add_attrs = true;
   3615       return NULL_TREE;
   3616     }
   3617   if (TARGET_64BIT)
   3618     {
   3619       warning (OPT_Wattributes, "%qE attribute only available for 32-bit",
   3620 	       name);
   3621       *no_add_attrs = true;
   3622       return NULL_TREE;
   3623     }
   3624   if (is_attribute_p ("callee_pop_aggregate_return", name))
   3625     {
   3626       tree cst;
   3627 
   3628       cst = TREE_VALUE (args);
   3629       if (TREE_CODE (cst) != INTEGER_CST)
   3630 	{
   3631 	  warning (OPT_Wattributes,
   3632 		   "%qE attribute requires an integer constant argument",
   3633 		   name);
   3634 	  *no_add_attrs = true;
   3635 	}
   3636       else if (compare_tree_int (cst, 0) != 0
   3637 	       && compare_tree_int (cst, 1) != 0)
   3638 	{
   3639 	  warning (OPT_Wattributes,
   3640 		   "argument to %qE attribute is neither zero, nor one",
   3641 		   name);
   3642 	  *no_add_attrs = true;
   3643 	}
   3644 
   3645       return NULL_TREE;
   3646     }
   3647 
   3648   return NULL_TREE;
   3649 }
   3650 
   3651 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
   3652    struct attribute_spec.handler.  */
   3653 
   3654 static tree
   3655 ix86_handle_abi_attribute (tree *node, tree name, tree, int,
   3656 			   bool *no_add_attrs)
   3657 {
   3658   if (TREE_CODE (*node) != FUNCTION_TYPE
   3659       && TREE_CODE (*node) != METHOD_TYPE
   3660       && TREE_CODE (*node) != FIELD_DECL
   3661       && TREE_CODE (*node) != TYPE_DECL)
   3662     {
   3663       warning (OPT_Wattributes, "%qE attribute only applies to functions",
   3664 	       name);
   3665       *no_add_attrs = true;
   3666       return NULL_TREE;
   3667     }
   3668 
   3669   /* Can combine regparm with all attributes but fastcall.  */
   3670   if (is_attribute_p ("ms_abi", name))
   3671     {
   3672       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
   3673         {
   3674 	  error ("%qs and %qs attributes are not compatible",
   3675 		 "ms_abi", "sysv_abi");
   3676 	}
   3677 
   3678       return NULL_TREE;
   3679     }
   3680   else if (is_attribute_p ("sysv_abi", name))
   3681     {
   3682       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
   3683         {
   3684 	  error ("%qs and %qs attributes are not compatible",
   3685 		 "ms_abi", "sysv_abi");
   3686 	}
   3687 
   3688       return NULL_TREE;
   3689     }
   3690 
   3691   return NULL_TREE;
   3692 }
   3693 
   3694 static tree
   3695 ix86_handle_fndecl_attribute (tree *node, tree name, tree args, int,
   3696 			      bool *no_add_attrs)
   3697 {
   3698   if (TREE_CODE (*node) != FUNCTION_DECL)
   3699     {
   3700       warning (OPT_Wattributes, "%qE attribute only applies to functions",
   3701                name);
   3702       *no_add_attrs = true;
   3703     }
   3704 
   3705   if (is_attribute_p ("indirect_branch", name))
   3706     {
   3707       tree cst = TREE_VALUE (args);
   3708       if (TREE_CODE (cst) != STRING_CST)
   3709 	{
   3710 	  warning (OPT_Wattributes,
   3711 		   "%qE attribute requires a string constant argument",
   3712 		   name);
   3713 	  *no_add_attrs = true;
   3714 	}
   3715       else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0
   3716 	       && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0
   3717 	       && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0
   3718 	       && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0)
   3719 	{
   3720 	  warning (OPT_Wattributes,
   3721 		   "argument to %qE attribute is not "
   3722 		   "(keep|thunk|thunk-inline|thunk-extern)", name);
   3723 	  *no_add_attrs = true;
   3724 	}
   3725     }
   3726 
   3727   if (is_attribute_p ("function_return", name))
   3728     {
   3729       tree cst = TREE_VALUE (args);
   3730       if (TREE_CODE (cst) != STRING_CST)
   3731 	{
   3732 	  warning (OPT_Wattributes,
   3733 		   "%qE attribute requires a string constant argument",
   3734 		   name);
   3735 	  *no_add_attrs = true;
   3736 	}
   3737       else if (strcmp (TREE_STRING_POINTER (cst), "keep") != 0
   3738 	       && strcmp (TREE_STRING_POINTER (cst), "thunk") != 0
   3739 	       && strcmp (TREE_STRING_POINTER (cst), "thunk-inline") != 0
   3740 	       && strcmp (TREE_STRING_POINTER (cst), "thunk-extern") != 0)
   3741 	{
   3742 	  warning (OPT_Wattributes,
   3743 		   "argument to %qE attribute is not "
   3744 		   "(keep|thunk|thunk-inline|thunk-extern)", name);
   3745 	  *no_add_attrs = true;
   3746 	}
   3747     }
   3748 
   3749   return NULL_TREE;
   3750 }
   3751 
   3752 static tree
   3753 ix86_handle_no_caller_saved_registers_attribute (tree *, tree, tree,
   3754 						 int, bool *)
   3755 {
   3756   return NULL_TREE;
   3757 }
   3758 
   3759 static tree
   3760 ix86_handle_interrupt_attribute (tree *node, tree, tree, int, bool *)
   3761 {
   3762   /* DECL_RESULT and DECL_ARGUMENTS do not exist there yet,
   3763      but the function type contains args and return type data.  */
   3764   tree func_type = *node;
   3765   tree return_type = TREE_TYPE (func_type);
   3766 
   3767   int nargs = 0;
   3768   tree current_arg_type = TYPE_ARG_TYPES (func_type);
   3769   while (current_arg_type
   3770 	 && ! VOID_TYPE_P (TREE_VALUE (current_arg_type)))
   3771     {
   3772       if (nargs == 0)
   3773 	{
   3774 	  if (! POINTER_TYPE_P (TREE_VALUE (current_arg_type)))
   3775 	    error ("interrupt service routine should have a pointer "
   3776 		   "as the first argument");
   3777 	}
   3778       else if (nargs == 1)
   3779 	{
   3780 	  if (TREE_CODE (TREE_VALUE (current_arg_type)) != INTEGER_TYPE
   3781 	      || TYPE_MODE (TREE_VALUE (current_arg_type)) != word_mode)
   3782 	    error ("interrupt service routine should have %qs "
   3783 		   "as the second argument",
   3784 		   TARGET_64BIT
   3785 		   ? (TARGET_X32 ? "unsigned long long int"
   3786 				 : "unsigned long int")
   3787 		   : "unsigned int");
   3788 	}
   3789       nargs++;
   3790       current_arg_type = TREE_CHAIN (current_arg_type);
   3791     }
   3792   if (!nargs || nargs > 2)
   3793     error ("interrupt service routine can only have a pointer argument "
   3794 	   "and an optional integer argument");
   3795   if (! VOID_TYPE_P (return_type))
   3796     error ("interrupt service routine must return %<void%>");
   3797 
   3798   return NULL_TREE;
   3799 }
   3800 
   3801 /* Handle fentry_name / fentry_section attribute.  */
   3802 
   3803 static tree
   3804 ix86_handle_fentry_name (tree *node, tree name, tree args,
   3805 			 int, bool *no_add_attrs)
   3806 {
   3807   if (TREE_CODE (*node) == FUNCTION_DECL
   3808       && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
   3809     /* Do nothing else, just set the attribute.  We'll get at
   3810        it later with lookup_attribute.  */
   3811     ;
   3812   else
   3813     {
   3814       warning (OPT_Wattributes, "%qE attribute ignored", name);
   3815       *no_add_attrs = true;
   3816     }
   3817 
   3818   return NULL_TREE;
   3819 }
   3820 
   3821 /* Handle a "nodirect_extern_access" attribute; arguments as in
   3822    struct attribute_spec.handler.  */
   3823 
   3824 static tree
   3825 handle_nodirect_extern_access_attribute (tree *pnode, tree name,
   3826 					 tree ARG_UNUSED (args),
   3827 					 int ARG_UNUSED (flags),
   3828 					 bool *no_add_attrs)
   3829 {
   3830   tree node = *pnode;
   3831 
   3832   if (VAR_OR_FUNCTION_DECL_P (node))
   3833     {
   3834       if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL
   3835 	   && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node))
   3836 	{
   3837 	  warning (OPT_Wattributes,
   3838 		   "%qE attribute have effect only on public objects", name);
   3839 	  *no_add_attrs = true;
   3840 	}
   3841     }
   3842   else
   3843     {
   3844       warning (OPT_Wattributes, "%qE attribute ignored", name);
   3845       *no_add_attrs = true;
   3846     }
   3847 
   3848   return NULL_TREE;
   3849 }
   3850 
   3851 /* Table of valid machine attributes.  */
   3852 const struct attribute_spec ix86_attribute_table[] =
   3853 {
   3854   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
   3855        affects_type_identity, handler, exclude } */
   3856   /* Stdcall attribute says callee is responsible for popping arguments
   3857      if they are not variable.  */
   3858   { "stdcall",   0, 0, false, true,  true,  true, ix86_handle_cconv_attribute,
   3859     NULL },
   3860   /* Fastcall attribute says callee is responsible for popping arguments
   3861      if they are not variable.  */
   3862   { "fastcall",  0, 0, false, true,  true,  true, ix86_handle_cconv_attribute,
   3863     NULL },
   3864   /* Thiscall attribute says callee is responsible for popping arguments
   3865      if they are not variable.  */
   3866   { "thiscall",  0, 0, false, true,  true,  true, ix86_handle_cconv_attribute,
   3867     NULL },
   3868   /* Cdecl attribute says the callee is a normal C declaration */
   3869   { "cdecl",     0, 0, false, true,  true,  true, ix86_handle_cconv_attribute,
   3870     NULL },
   3871   /* Regparm attribute specifies how many integer arguments are to be
   3872      passed in registers.  */
   3873   { "regparm",   1, 1, false, true,  true,  true, ix86_handle_cconv_attribute,
   3874     NULL },
   3875   /* Sseregparm attribute says we are using x86_64 calling conventions
   3876      for FP arguments.  */
   3877   { "sseregparm", 0, 0, false, true, true,  true, ix86_handle_cconv_attribute,
   3878     NULL },
   3879   /* The transactional memory builtins are implicitly regparm or fastcall
   3880      depending on the ABI.  Override the generic do-nothing attribute that
   3881      these builtins were declared with.  */
   3882   { "*tm regparm", 0, 0, false, true, true, true,
   3883     ix86_handle_tm_regparm_attribute, NULL },
   3884   /* force_align_arg_pointer says this function realigns the stack at entry.  */
   3885   { "force_align_arg_pointer", 0, 0,
   3886     false, true,  true, false, ix86_handle_force_align_arg_pointer_attribute,
   3887     NULL },
   3888 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
   3889   { "dllimport", 0, 0, false, false, false, false, handle_dll_attribute,
   3890     NULL },
   3891   { "dllexport", 0, 0, false, false, false, false, handle_dll_attribute,
   3892     NULL },
   3893   { "shared",    0, 0, true,  false, false, false,
   3894     ix86_handle_shared_attribute, NULL },
   3895 #endif
   3896   { "ms_struct", 0, 0, false, false,  false, false,
   3897     ix86_handle_struct_attribute, NULL },
   3898   { "gcc_struct", 0, 0, false, false,  false, false,
   3899     ix86_handle_struct_attribute, NULL },
   3900 #ifdef SUBTARGET_ATTRIBUTE_TABLE
   3901   SUBTARGET_ATTRIBUTE_TABLE,
   3902 #endif
   3903   /* ms_abi and sysv_abi calling convention function attributes.  */
   3904   { "ms_abi", 0, 0, false, true, true, true, ix86_handle_abi_attribute, NULL },
   3905   { "sysv_abi", 0, 0, false, true, true, true, ix86_handle_abi_attribute,
   3906     NULL },
   3907   { "ms_abi va_list", 0, 0, false, false, false, false, NULL, NULL },
   3908   { "sysv_abi va_list", 0, 0, false, false, false, false, NULL, NULL },
   3909   { "ms_hook_prologue", 0, 0, true, false, false, false,
   3910     ix86_handle_fndecl_attribute, NULL },
   3911   { "callee_pop_aggregate_return", 1, 1, false, true, true, true,
   3912     ix86_handle_callee_pop_aggregate_return, NULL },
   3913   { "interrupt", 0, 0, false, true, true, false,
   3914     ix86_handle_interrupt_attribute, NULL },
   3915   { "no_caller_saved_registers", 0, 0, false, true, true, false,
   3916     ix86_handle_no_caller_saved_registers_attribute, NULL },
   3917   { "naked", 0, 0, true, false, false, false,
   3918     ix86_handle_fndecl_attribute, NULL },
   3919   { "indirect_branch", 1, 1, true, false, false, false,
   3920     ix86_handle_fndecl_attribute, NULL },
   3921   { "function_return", 1, 1, true, false, false, false,
   3922     ix86_handle_fndecl_attribute, NULL },
   3923   { "indirect_return", 0, 0, false, true, true, false,
   3924     NULL, NULL },
   3925   { "fentry_name", 1, 1, true, false, false, false,
   3926     ix86_handle_fentry_name, NULL },
   3927   { "fentry_section", 1, 1, true, false, false, false,
   3928     ix86_handle_fentry_name, NULL },
   3929   { "cf_check", 0, 0, true, false, false, false,
   3930     ix86_handle_fndecl_attribute, NULL },
   3931   { "nodirect_extern_access", 0, 0, true, false, false, false,
   3932     handle_nodirect_extern_access_attribute, NULL },
   3933 
   3934   /* End element.  */
   3935   { NULL, 0, 0, false, false, false, false, NULL, NULL }
   3936 };
   3937 
   3938 #include "gt-i386-options.h"
   3939