* gimplify.c (nonlocal_vlas): Delete.
[official-gcc.git] / gcc / config / s390 / driver-native.c
blob3793f8a6c275cc1a2dac2d7c161d5de4f4041ca1
1 /* Subroutines for the gcc driver.
2 Copyright (C) 2015-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #define IN_TARGET_CODE 1
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
27 /* This will be called by the spec parser in gcc.c when it sees
28 a %:local_cpu_detect(args) construct. Currently it will be called
29 with either "arch" or "tune" as argument depending on if -march=native
30 or -mtune=native is to be substituted.
32 It returns a string containing new command line parameters to be
33 put at the place of the above two options, depending on what CPU
34 this is executed. E.g. "-march=zEC12" on a zEC12 for -march=native.
35 If the routine can't detect a known processor, the -march or -mtune
36 option is discarded.
38 ARGC and ARGV are set depending on the actual arguments given
39 in the spec. */
40 const char *
41 s390_host_detect_local_cpu (int argc, const char **argv)
43 const char *cpu = NULL;
44 char buf[256];
45 FILE *f;
46 bool arch;
47 const char *options = "";
48 unsigned int has_features;
49 unsigned int has_processor;
50 unsigned int is_cpu_z9_109 = 0;
51 unsigned int has_highgprs = 0;
52 unsigned int has_dfp = 0;
53 unsigned int has_te = 0;
54 unsigned int has_vx = 0;
55 unsigned int has_opt_esa_zarch = 0;
56 int i;
58 if (argc < 1)
59 return NULL;
61 arch = strcmp (argv[0], "arch") == 0;
62 if (!arch && strcmp (argv[0], "tune"))
63 return NULL;
64 for (i = 1; i < argc; i++)
65 if (strcmp (argv[i], "mesa_mzarch") == 0)
66 has_opt_esa_zarch = 1;
68 f = fopen ("/proc/cpuinfo", "r");
69 if (f == NULL)
70 return NULL;
72 for (has_features = 0, has_processor = 0;
73 (has_features == 0 || has_processor == 0)
74 && fgets (buf, sizeof (buf), f) != NULL; )
76 if (has_processor == 0 && strncmp (buf, "processor", 9) == 0)
78 const char *p;
79 long machine_id;
81 p = strstr (buf, "machine = ");
82 if (p == NULL)
83 continue;
84 p += 10;
85 has_processor = 1;
86 machine_id = strtol (p, NULL, 16);
87 switch (machine_id)
89 /* g5 and g6 default to z900 */
90 case 0x9672:
91 case 0x2064:
92 case 0x2066:
93 cpu = "z900";
94 break;
95 case 0x2084:
96 case 0x2086:
97 cpu = "z990";
98 break;
99 case 0x2094:
100 case 0x2096:
101 cpu = "z9-109";
102 is_cpu_z9_109 = 1;
103 break;
104 case 0x2097:
105 case 0x2098:
106 cpu = "z10";
107 break;
108 case 0x2817:
109 case 0x2818:
110 cpu = "z196";
111 break;
112 case 0x2827:
113 case 0x2828:
114 cpu = "zEC12";
115 break;
116 case 0x2964:
117 case 0x2965:
118 cpu = "z13";
119 break;
120 case 0x3906:
121 cpu = "z14";
122 break;
123 default:
124 cpu = "z14";
125 break;
128 if (has_features == 0 && strncmp (buf, "features", 8) == 0)
130 const char *p;
132 p = strchr (buf, ':');
133 if (p == NULL)
134 continue;
135 p++;
136 while (*p != 0)
138 int i;
140 while (ISSPACE (*p))
141 p++;
142 for (i = 0; !ISSPACE (p[i]) && p[i] != 0; i++)
144 if (i == 3 && strncmp (p, "dfp", 3) == 0)
145 has_dfp = 1;
146 else if (i == 2 && strncmp (p, "te", 2) == 0)
147 has_te = 1;
148 else if (i == 2 && strncmp (p, "vx", 2) == 0)
149 has_vx = 1;
150 else if (i == 8 && strncmp (p, "highgprs", 8) == 0)
151 has_highgprs = 1;
152 p += i;
154 has_features = 1;
158 fclose (f);
160 if (cpu == NULL)
161 return NULL;
163 if (arch)
165 const char *opt_htm = "";
166 const char *opt_vx = "";
167 const char *opt_esa_zarch = "";
169 /* We may switch off these cpu features but never switch the on
170 explicitly. This overrides options specified on the command line. */
171 if (!has_te)
172 opt_htm = " -mno-htm";
173 if (!has_vx)
174 opt_vx = " -mno-vx";
175 /* However, we set -mzarch only if neither -mzarch nor -mesa are used on
176 the command line. This allows the user to switch to -mesa manually.
178 if (!has_opt_esa_zarch && has_highgprs)
179 opt_esa_zarch = " -mzarch";
180 options = concat (options, opt_htm, opt_vx, opt_esa_zarch, NULL);
182 if (has_dfp && is_cpu_z9_109)
183 cpu = "z9-ec";
185 return concat ("-m", argv[0], "=", cpu, options, NULL);