2008-07-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[official-gcc.git] / gcc / config / mips / driver-native.c
blob22b08939e245c052bd4c29f3f039727aa5f186ed
1 /* Subroutines for the gcc driver.
2 Copyright (C) 2008 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 #include "config.h"
21 #include "system.h"
23 /* This will be called by the spec parser in gcc.c when it sees
24 a %:local_cpu_detect(args) construct. Currently it will be called
25 with either "arch" or "tune" as argument depending on if -march=native
26 or -mtune=native is to be substituted.
28 It returns a string containing new command line parameters to be
29 put at the place of the above two options, depending on what CPU
30 this is executed. E.g. "-march=loongson2f" on a Loongson 2F for
31 -march=native. If the routine can't detect a known processor,
32 the -march or -mtune option is discarded.
34 ARGC and ARGV are set depending on the actual arguments given
35 in the spec. */
36 const char *
37 host_detect_local_cpu (int argc, const char **argv)
39 const char *cpu = NULL;
40 char buf[128];
41 FILE *f;
42 bool arch;
44 if (argc < 1)
45 return NULL;
47 arch = strcmp (argv[0], "arch") == 0;
48 if (!arch && strcmp (argv[0], "tune"))
49 return NULL;
51 f = fopen ("/proc/cpuinfo", "r");
52 if (f == NULL)
53 return NULL;
55 while (fgets (buf, sizeof (buf), f) != NULL)
56 if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0)
58 if (strstr (buf, "Godson2 V0.2") != NULL
59 || strstr (buf, "Loongson-2 V0.2") != NULL)
60 cpu = "loongson2e";
61 else if (strstr (buf, "Godson2 V0.3") != NULL
62 || strstr (buf, "Loongson-2 V0.3") != NULL)
63 cpu = "loongson2f";
64 break;
67 fclose (f);
69 if (cpu == NULL)
70 return NULL;
72 return concat ("-m", argv[0], "=", cpu, NULL);