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