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)
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/>. */
22 #include "coretypes.h"
24 #include "common/common-target.h"
25 #include "common/common-target-def.h"
28 #include "diagnostic-core.h"
30 /* Parse a RISC-V ISA string into an option mask. Must clear or set all arch
31 dependent mask bits, in case more than one -march string is passed. */
34 riscv_parse_arch_string (const char *isa
, int *flags
, location_t loc
)
38 if (strncmp (p
, "rv32", 4) == 0)
39 *flags
&= ~MASK_64BIT
, p
+= 4;
40 else if (strncmp (p
, "rv64", 4) == 0)
41 *flags
|= MASK_64BIT
, p
+= 4;
44 error_at (loc
, "-march=%s: ISA string must begin with rv32 or rv64", isa
);
55 *flags
|= MASK_ATOMIC
;
56 *flags
|= MASK_HARD_FLOAT
;
57 *flags
|= MASK_DOUBLE_FLOAT
;
67 *flags
|= MASK_MUL
, p
++;
69 *flags
&= ~MASK_ATOMIC
;
71 *flags
|= MASK_ATOMIC
, p
++;
73 *flags
&= ~(MASK_HARD_FLOAT
| MASK_DOUBLE_FLOAT
);
76 *flags
|= MASK_HARD_FLOAT
, p
++;
80 *flags
|= MASK_DOUBLE_FLOAT
;
91 if (*flags
& MASK_64BIT
)
93 error ("RV64E is not a valid base ISA");
99 *flags
|= MASK_MUL
, p
++;
101 *flags
&= ~MASK_ATOMIC
;
103 *flags
|= MASK_ATOMIC
, p
++;
105 *flags
&= ~(MASK_HARD_FLOAT
| MASK_DOUBLE_FLOAT
);
109 error_at (loc
, "-march=%s: invalid ISA string", isa
);
115 *flags
|= MASK_RVC
, p
++;
119 error_at (loc
, "-march=%s: unsupported ISA substring %qs", isa
, p
);
124 /* Implement TARGET_HANDLE_OPTION. */
127 riscv_handle_option (struct gcc_options
*opts
,
128 struct gcc_options
*opts_set ATTRIBUTE_UNUSED
,
129 const struct cl_decoded_option
*decoded
,
132 switch (decoded
->opt_index
)
135 riscv_parse_arch_string (decoded
->arg
, &opts
->x_target_flags
, loc
);
143 /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
144 static const struct default_options riscv_option_optimization_table
[] =
146 { OPT_LEVELS_1_PLUS
, OPT_fsection_anchors
, NULL
, 1 },
147 { OPT_LEVELS_2_PLUS
, OPT_free
, NULL
, 1 },
148 { OPT_LEVELS_NONE
, 0, NULL
, 0 }
151 #undef TARGET_OPTION_OPTIMIZATION_TABLE
152 #define TARGET_OPTION_OPTIMIZATION_TABLE riscv_option_optimization_table
154 #undef TARGET_HANDLE_OPTION
155 #define TARGET_HANDLE_OPTION riscv_handle_option
157 struct gcc_targetm_common targetm_common
= TARGETM_COMMON_INITIALIZER
;