RISC-V: Support to add implicit extensions.
authorNelson Chu <nelson.chu@sifive.com>
Fri, 20 Nov 2020 10:05:05 +0000 (18:05 +0800)
committerNelson Chu <nelson.chu@sifive.com>
Tue, 1 Dec 2020 07:18:48 +0000 (15:18 +0800)
commitdfe92496678a200464e54d80e96a608bfea338b9
treebdb1591a6dc6f76a781ffaaf2abef7663852f1b4
parent7ef19aa616aee98f0a5c7c948d0db56a9f3c5e57
RISC-V: Support to add implicit extensions.

We have to parse and add all arch string extensions at first, and then
start to add their implicit extensions.  That means we can always add
arch string extensions at the end of the subset list, but we need to
search the right place to add their implicit extensions.  For now we
follow the following rules to add the implicit extensions,

* Add zicsr and zifencei only when the i's version less than 2.1.
* Add d, f and zicsr when q is found.
* Add f and zicsr when d is found.
* Add zicsr when f is found.

Besides, we do not add the implicit extensions if they are already added
in the subset list, or we cannot find their default versions according to
the chosen ISA spec.

bfd/
* elfnn-riscv.c (riscv_merge_std_ext): Updated since
riscv_lookup_subset is changed.
* elfxx-riscv.c (riscv_ext_order): New Array used to compare the
extensions' order quickly.
(riscv_init_ext_order): New function.  Init the riscv_ext_order
according to the riscv_supported_std_ext and parse_config[i].class
automatically.
(riscv_compare_subsets): New function.  Similar to the strcmp, but
compare the subsets with the specific order.
(riscv_lookup_subset): Return TRUE and set `current` to the subset
if it is found.  Otherwise, return FALSE and set `current` to the
place where we should insert the subset.
(riscv_add_implicit_subset): New function.  Search the list first,
and then find the right place to add the implicit_subset.
(riscv_parse_add_subset): Since We have to add all arch string
extensions first, and then start to add their implicit extensions.
We can add arch string extensions in order by the original
riscv_add_subset, and then add the implicit subsets by the
riscv_add_implicit_subset.  Besides, do not add the implicit
extensions if we failed to find their default versions.
(riscv_parse_std_ext): Updated.
(riscv_parse_add_implicit_subsets): New function.  Add all implicit
extensions according to the arch string extensions.
(riscv_parse_subset): Call riscv_init_ext_order and
riscv_parse_add_implicit_subsets, before and after parsing the
arch string.  Remove parts of the ISA conflict checking since
the implicit extensions are added.
* elfxx-riscv.h (riscv_lookup_subset): Updated.

gas/
* config/tc-riscv.c (riscv_subset_supports): Updated.
* testsuite/gas/riscv/march-imply-i2p0.d: New testcase.  Need to
add the implicit zicsr and zifencei when i's version less than 2.1.
* testsuite/gas/riscv/march-imply-i2p1.d: New testcase.
* testsuite/gas/riscv/march-imply-d.d: Likewise.
* testsuite/gas/riscv/march-imply-f.d: Likewise.
* testsuite/gas/riscv/march-imply-q.d: Likewise.
* testsuite/gas/riscv/march-fail-rv32iq.l: Updated.
* testsuite/gas/riscv/march-fail-rv32id.d: Removed.
* testsuite/gas/riscv/march-fail-rv32id.l: Likewise.
* testsuite/gas/riscv/march-fail-rv64iq.d: Likewise.
* testsuite/gas/riscv/march-fail-rv64iq.l: Likewise.
16 files changed:
bfd/ChangeLog
bfd/elfnn-riscv.c
bfd/elfxx-riscv.c
bfd/elfxx-riscv.h
gas/ChangeLog
gas/config/tc-riscv.c
gas/testsuite/gas/riscv/march-fail-rv32id.d [deleted file]
gas/testsuite/gas/riscv/march-fail-rv32id.l [deleted file]
gas/testsuite/gas/riscv/march-fail-rv32iq.l
gas/testsuite/gas/riscv/march-fail-rv64iq.d [deleted file]
gas/testsuite/gas/riscv/march-fail-rv64iq.l [deleted file]
gas/testsuite/gas/riscv/march-imply-d.d [new file with mode: 0644]
gas/testsuite/gas/riscv/march-imply-f.d [new file with mode: 0644]
gas/testsuite/gas/riscv/march-imply-i2p0.d [new file with mode: 0644]
gas/testsuite/gas/riscv/march-imply-i2p1.d [new file with mode: 0644]
gas/testsuite/gas/riscv/march-imply-q.d [new file with mode: 0644]