Skip to content

Commit 6b572d4

Browse files
cyyselfkito-cheng
authored andcommitted
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 Signed-off-by: Yangyu Chen <[email protected]> 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. * config/riscv/riscv.opt: Add TargetVariable riscv_fmv_priority.
1 parent 9bf0dbe commit 6b572d4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 24 additions & 0 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

@@ -210,6 +215,22 @@ riscv_target_attr_parser::handle_tune (const char *str)
210215
return true;
211216
}
212217

218+
bool
219+
riscv_target_attr_parser::handle_priority (const char *str)
220+
{
221+
if (m_found_priority_p)
222+
error_at (m_loc, "%<target()%> attribute: priority appears more than once");
223+
m_found_priority_p = true;
224+
225+
if (sscanf (str, "%d", &m_priority) != 1)
226+
{
227+
error_at (m_loc, "%<target()%> attribute: invalid priority %qs", str);
228+
return false;
229+
}
230+
231+
return true;
232+
}
233+
213234
void
214235
riscv_target_attr_parser::update_settings (struct gcc_options *opts) const
215236
{
@@ -236,6 +257,9 @@ riscv_target_attr_parser::update_settings (struct gcc_options *opts) const
236257
if (m_cpu_info)
237258
opts->x_riscv_tune_string = m_cpu_info->tune;
238259
}
260+
261+
if (m_priority)
262+
opts->x_riscv_fmv_priority = m_priority;
239263
}
240264

241265
/* Parse ARG_STR which contains the definition of one target attribute.

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)