]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/common/config/riscv/riscv-common.c
Update copyright years.
[thirdparty/gcc.git] / gcc / common / config / riscv / riscv-common.c
CommitLineData
09cae750 1/* Common hooks for RISC-V.
85ec4feb 2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
09cae750
PD
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
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"
29
30/* Parse a RISC-V ISA string into an option mask. */
31
32static void
33riscv_parse_arch_string (const char *isa, int *flags, location_t loc)
34{
35 const char *p = isa;
36
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
42 {
43 error_at (loc, "-march=%s: ISA string must begin with rv32 or rv64", isa);
44 return;
45 }
46
47 if (*p == 'g')
48 {
49 p++;
50
51 *flags |= MASK_MUL;
52 *flags |= MASK_ATOMIC;
53 *flags |= MASK_HARD_FLOAT;
54 *flags |= MASK_DOUBLE_FLOAT;
55 }
56 else if (*p == 'i')
57 {
58 p++;
59
60 *flags &= ~MASK_MUL;
61 if (*p == 'm')
62 *flags |= MASK_MUL, p++;
63
64 *flags &= ~MASK_ATOMIC;
65 if (*p == 'a')
66 *flags |= MASK_ATOMIC, p++;
67
68 *flags &= ~(MASK_HARD_FLOAT | MASK_DOUBLE_FLOAT);
69 if (*p == 'f')
70 {
71 *flags |= MASK_HARD_FLOAT, p++;
72
73 if (*p == 'd')
74 {
75 *flags |= MASK_DOUBLE_FLOAT;
76 p++;
77 }
78 }
79 }
80 else
81 {
82 error_at (loc, "-march=%s: invalid ISA string", isa);
83 return;
84 }
85
86 *flags &= ~MASK_RVC;
87 if (*p == 'c')
88 *flags |= MASK_RVC, p++;
89
90 if (*p)
91 {
92 error_at (loc, "-march=%s: unsupported ISA substring %qs", isa, p);
93 return;
94 }
95}
96
97/* Implement TARGET_HANDLE_OPTION. */
98
99static bool
100riscv_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)
104{
105 switch (decoded->opt_index)
106 {
107 case OPT_march_:
108 riscv_parse_arch_string (decoded->arg, &opts->x_target_flags, loc);
109 return true;
110
111 default:
112 return true;
113 }
114}
115
116/* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
117static const struct default_options riscv_option_optimization_table[] =
118 {
119 { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 1 },
09cae750
PD
120 { OPT_LEVELS_2_PLUS, OPT_free, NULL, 1 },
121 { OPT_LEVELS_NONE, 0, NULL, 0 }
122 };
123
124#undef TARGET_OPTION_OPTIMIZATION_TABLE
125#define TARGET_OPTION_OPTIMIZATION_TABLE riscv_option_optimization_table
126
127#undef TARGET_HANDLE_OPTION
128#define TARGET_HANDLE_OPTION riscv_handle_option
129
130struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;