2018-04-24 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / gcc / common / config / riscv / riscv-common.c
blob9db83015aedea26bc94bc83963280c7e82e0e4dc
1 /* Common hooks for RISC-V.
2 Copyright (C) 2016-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 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "common/common-target.h"
25 #include "common/common-target-def.h"
26 #include "opts.h"
27 #include "flags.h"
28 #include "diagnostic-core.h"
30 /* Parse a RISC-V ISA string into an option mask. */
32 static void
33 riscv_parse_arch_string (const char *isa, int *flags, location_t loc)
35 const char *p = isa;
37 if (strncmp (p, "rv32", 4) == 0)
38 *flags &= ~MASK_64BIT, p += 4;
39 else if (strncmp (p, "rv64", 4) == 0)
40 *flags |= MASK_64BIT, p += 4;
41 else
43 error_at (loc, "-march=%s: ISA string must begin with rv32 or rv64", isa);
44 return;
47 if (*p == 'g')
49 p++;
51 *flags |= MASK_MUL;
52 *flags |= MASK_ATOMIC;
53 *flags |= MASK_HARD_FLOAT;
54 *flags |= MASK_DOUBLE_FLOAT;
56 else if (*p == 'i')
58 p++;
60 *flags &= ~MASK_MUL;
61 if (*p == 'm')
62 *flags |= MASK_MUL, p++;
64 *flags &= ~MASK_ATOMIC;
65 if (*p == 'a')
66 *flags |= MASK_ATOMIC, p++;
68 *flags &= ~(MASK_HARD_FLOAT | MASK_DOUBLE_FLOAT);
69 if (*p == 'f')
71 *flags |= MASK_HARD_FLOAT, p++;
73 if (*p == 'd')
75 *flags |= MASK_DOUBLE_FLOAT;
76 p++;
80 else
82 error_at (loc, "-march=%s: invalid ISA string", isa);
83 return;
86 *flags &= ~MASK_RVC;
87 if (*p == 'c')
88 *flags |= MASK_RVC, p++;
90 if (*p)
92 error_at (loc, "-march=%s: unsupported ISA substring %qs", isa, p);
93 return;
97 /* Implement TARGET_HANDLE_OPTION. */
99 static bool
100 riscv_handle_option (struct gcc_options *opts,
101 struct gcc_options *opts_set ATTRIBUTE_UNUSED,
102 const struct cl_decoded_option *decoded,
103 location_t loc)
105 switch (decoded->opt_index)
107 case OPT_march_:
108 riscv_parse_arch_string (decoded->arg, &opts->x_target_flags, loc);
109 return true;
111 default:
112 return true;
116 /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
117 static const struct default_options riscv_option_optimization_table[] =
119 { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
120 { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
121 { OPT_LEVELS_NONE, 0, NULL, 0 }
124 #undef TARGET_OPTION_OPTIMIZATION_TABLE
125 #define TARGET_OPTION_OPTIMIZATION_TABLE riscv_option_optimization_table
127 #undef TARGET_HANDLE_OPTION
128 #define TARGET_HANDLE_OPTION riscv_handle_option
130 struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;