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. */
33 riscv_parse_arch_string (const char *isa
, int *flags
, location_t loc
)
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;
43 error_at (loc
, "-march=%s: ISA string must begin with rv32 or rv64", isa
);
52 *flags
|= MASK_ATOMIC
;
53 *flags
|= MASK_HARD_FLOAT
;
54 *flags
|= MASK_DOUBLE_FLOAT
;
62 *flags
|= MASK_MUL
, p
++;
64 *flags
&= ~MASK_ATOMIC
;
66 *flags
|= MASK_ATOMIC
, p
++;
68 *flags
&= ~(MASK_HARD_FLOAT
| MASK_DOUBLE_FLOAT
);
71 *flags
|= MASK_HARD_FLOAT
, p
++;
75 *flags
|= MASK_DOUBLE_FLOAT
;
82 error_at (loc
, "-march=%s: invalid ISA string", isa
);
88 *flags
|= MASK_RVC
, p
++;
92 error_at (loc
, "-march=%s: unsupported ISA substring %qs", isa
, p
);
97 /* Implement TARGET_HANDLE_OPTION. */
100 riscv_handle_option (struct gcc_options
*opts
,
101 struct gcc_options
*opts_set ATTRIBUTE_UNUSED
,
102 const struct cl_decoded_option
*decoded
,
105 switch (decoded
->opt_index
)
108 riscv_parse_arch_string (decoded
->arg
, &opts
->x_target_flags
, loc
);
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
;