]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/arm/driver-arm.c
Update copyright years.
[thirdparty/gcc.git] / gcc / config / arm / driver-arm.c
CommitLineData
33aa08b3 1/* Subroutines for the gcc driver.
8d9254fc 2 Copyright (C) 2011-2020 Free Software Foundation, Inc.
33aa08b3
AS
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
8fcc61f8
RS
20#define IN_TARGET_CODE 1
21
33aa08b3
AS
22#include "config.h"
23#include "system.h"
24#include "coretypes.h"
25#include "tm.h"
26#include "configargs.h"
27
b02160e5
RE
28struct vendor_cpu
29{
33aa08b3
AS
30 const char *part_no;
31 const char *arch_name;
32 const char *cpu_name;
33};
34
b02160e5
RE
35struct vendor
36{
33aa08b3
AS
37 const char *vendor_no;
38 const struct vendor_cpu *vendor_parts;
33aa08b3
AS
39};
40
b02160e5
RE
41#include "arm-native.h"
42
33aa08b3
AS
43/* This will be called by the spec parser in gcc.c when it sees
44 a %:local_cpu_detect(args) construct. Currently it will be called
45 with either "arch", "cpu" or "tune" as argument depending on if
46 -march=native, -mcpu=native or -mtune=native is to be substituted.
47
48 It returns a string containing new command line parameters to be
49 put at the place of the above two options, depending on what CPU
50 this is executed. E.g. "-march=armv7-a" on a Cortex-A8 for
51 -march=native. If the routine can't detect a known processor,
52 the -march or -mtune option is discarded.
53
54 ARGC and ARGV are set depending on the actual arguments given
55 in the spec. */
56const char *
57host_detect_local_cpu (int argc, const char **argv)
58{
59 const char *val = NULL;
60 char buf[128];
e9d662bb 61 FILE *f = NULL;
33aa08b3
AS
62 bool arch;
63 const struct vendor_cpu *cpu_table = NULL;
64
65 if (argc < 1)
66 goto not_found;
67
68 arch = strcmp (argv[0], "arch") == 0;
69 if (!arch && strcmp (argv[0], "cpu") != 0 && strcmp (argv[0], "tune"))
70 goto not_found;
71
72 f = fopen ("/proc/cpuinfo", "r");
73 if (f == NULL)
74 goto not_found;
75
76 while (fgets (buf, sizeof (buf), f) != NULL)
77 {
b02160e5 78 /* Find the vendor table associated with this implementer. */
33aa08b3
AS
79 if (strncmp (buf, "CPU implementer", sizeof ("CPU implementer") - 1) == 0)
80 {
81 int i;
b02160e5
RE
82 for (i = 0; vendors_table[i].vendor_no != NULL; i++)
83 if (strstr (buf, vendors_table[i].vendor_no) != NULL)
33aa08b3 84 {
b02160e5 85 cpu_table = vendors_table[i].vendor_parts;
33aa08b3
AS
86 break;
87 }
88 }
89
90 /* Detect arch/cpu. */
91 if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0)
92 {
93 int i;
94
95 if (cpu_table == NULL)
96 goto not_found;
97
98 for (i = 0; cpu_table[i].part_no != NULL; i++)
99 if (strstr (buf, cpu_table[i].part_no) != NULL)
100 {
101 val = arch ? cpu_table[i].arch_name : cpu_table[i].cpu_name;
102 break;
103 }
104 break;
105 }
106 }
107
6b32fd17
KT
108 if (val)
109 {
110 fclose (f);
111 return concat ("-m", argv[0], "=", val, NULL);
112 }
33aa08b3
AS
113
114not_found:
115 {
116 unsigned int i;
117 unsigned int opt;
118 const char *search[] = {NULL, "arch"};
6d3f1a13 119
e9d662bb
AS
120 if (f)
121 fclose (f);
6d3f1a13 122
33aa08b3
AS
123 search[0] = argv[0];
124 for (opt = 0; opt < ARRAY_SIZE (search); opt++)
125 for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
126 if (strcmp (configure_default_options[i].name, search[opt]) == 0)
127 return concat ("-m", search[opt], "=",
128 configure_default_options[i].value, NULL);
129 return NULL;
130 }
131}