Skip to content

Commit be40591

Browse files
committed
RISC-V: Implement Priority syntax parser for Function Multi-Versioning
This patch adds the priority syntax parser to support the Function Multi-Versioning (FMV) feature in RISC-V. This feature allows users to specify the priority of the function version in the attribute syntax. Chnages based on RISC-V C-API PR: riscv-non-isa/riscv-c-api-doc#85 gcc/ChangeLog: * config/riscv/riscv-target-attr.cc (riscv_target_attr_parser::handle_priority): New function. (riscv_target_attr_parser::update_settings): Update priority attribute. (riscv_process_one_target_attr): Add const qualifier to arg_str and split arg_str with ';'. * config/riscv/riscv.opt: Add TargetVariable riscv_fmv_priority.
1 parent d890613 commit be40591

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

gcc/config/riscv/riscv-target-attr.cc

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,19 @@ class riscv_target_attr_parser
3939
: m_found_arch_p (false)
4040
, m_found_tune_p (false)
4141
, m_found_cpu_p (false)
42+
, m_found_priority_p (false)
4243
, m_subset_list (nullptr)
4344
, m_loc (loc)
4445
, m_cpu_info (nullptr)
4546
, m_tune (nullptr)
47+
, m_priority (0)
4648
{
4749
}
4850

4951
bool handle_arch (const char *);
5052
bool handle_cpu (const char *);
5153
bool handle_tune (const char *);
54+
bool handle_priority (const char *);
5255

5356
void update_settings (struct gcc_options *opts) const;
5457
private:
@@ -58,10 +61,12 @@ class riscv_target_attr_parser
5861
bool m_found_arch_p;
5962
bool m_found_tune_p;
6063
bool m_found_cpu_p;
64+
bool m_found_priority_p;
6165
riscv_subset_list *m_subset_list;
6266
location_t m_loc;
6367
const riscv_cpu_info *m_cpu_info;
6468
const char *m_tune;
69+
int m_priority;
6570
};
6671
}
6772

@@ -80,7 +85,8 @@ struct riscv_attribute_info
8085
static const struct riscv_attribute_info riscv_attributes[]
8186
= {{"arch", &riscv_target_attr_parser::handle_arch},
8287
{"cpu", &riscv_target_attr_parser::handle_cpu},
83-
{"tune", &riscv_target_attr_parser::handle_tune}};
88+
{"tune", &riscv_target_attr_parser::handle_tune},
89+
{"priority", &riscv_target_attr_parser::handle_priority}};
8490

8591
bool
8692
riscv_target_attr_parser::parse_arch (const char *str)
@@ -210,6 +216,22 @@ riscv_target_attr_parser::handle_tune (const char *str)
210216
return true;
211217
}
212218

219+
bool
220+
riscv_target_attr_parser::handle_priority (const char *str)
221+
{
222+
if (m_found_priority_p)
223+
error_at (m_loc, "%<target()%> attribute: priority appears more than once");
224+
m_found_priority_p = true;
225+
226+
if (sscanf (str, "%d", &m_priority) != 1)
227+
{
228+
error_at (m_loc, "%<target()%> attribute: invalid priority %qs", str);
229+
return false;
230+
}
231+
232+
return true;
233+
}
234+
213235
void
214236
riscv_target_attr_parser::update_settings (struct gcc_options *opts) const
215237
{
@@ -236,13 +258,16 @@ riscv_target_attr_parser::update_settings (struct gcc_options *opts) const
236258
if (m_cpu_info)
237259
opts->x_riscv_tune_string = m_cpu_info->tune;
238260
}
261+
262+
if (m_priority)
263+
opts->x_riscv_fmv_priority = m_priority;
239264
}
240265

241266
/* Parse ARG_STR which contains the definition of one target attribute.
242267
Show appropriate errors if any or return true if the attribute is valid. */
243268

244269
static bool
245-
riscv_process_one_target_attr (char *arg_str,
270+
riscv_process_one_target_attr (const char *arg_str,
246271
location_t loc,
247272
riscv_target_attr_parser &attr_parser)
248273
{
@@ -271,6 +296,12 @@ riscv_process_one_target_attr (char *arg_str,
271296

272297
arg[0] = '\0';
273298
++arg;
299+
300+
/* Skip splitter ';' if it exists. */
301+
char *splitter = strchr (arg, ';');
302+
if (splitter)
303+
splitter[0] = '\0';
304+
274305
for (const auto &attr : riscv_attributes)
275306
{
276307
/* If the names don't match up, or the user has given an argument

gcc/config/riscv/riscv.opt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ Mask(XSFVCP) Var(riscv_sifive_subext)
523523

524524
Mask(XSFCEASE) Var(riscv_sifive_subext)
525525

526+
TargetVariable
527+
int riscv_fmv_priority = 0
528+
526529
Enum
527530
Name(isa_spec_class) Type(enum riscv_isa_spec_class)
528531
Supported ISA specs (for use with the -misa-spec= option):

0 commit comments

Comments
 (0)