This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Unify depedency check and extension implication parsing logics
ClosedPublic

Authored by eopXD on Oct 23 2021, 3:18 AM.

Details

Summary

Originially there are two places that does parsing - parseArchString and
parseFeatures, each with its code on dependency check and implication.
This patch extracts common parts of the two as functions of RISCVISAInfo
and let them 2 use it.

Diff Detail

Event Timeline

eopXD created this revision.Oct 23 2021, 3:18 AM
eopXD requested review of this revision.Oct 23 2021, 3:18 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 23 2021, 3:18 AM
eopXD retitled this revision from [RISCV] Unify depedency check and extension implication parsing logics to [NFC][RISCV] Unify depedency check and extension implication parsing logics.Oct 23 2021, 4:41 AM
eopXD edited the summary of this revision. (Show Details)
eopXD updated this revision to Diff 381742.Oct 23 2021, 8:49 AM

Rebase.

eopXD updated this revision to Diff 381744.Oct 23 2021, 8:50 AM

Minor update.

eopXD updated this revision to Diff 381745.Oct 23 2021, 8:52 AM

Remove debug code.

eopXD updated this revision to Diff 381866.Oct 25 2021, 12:31 AM

Update clang-format.

eopXD retitled this revision from [NFC][RISCV] Unify depedency check and extension implication parsing logics to [RISCV] Unify depedency check and extension implication parsing logics.Oct 25 2021, 1:15 AM
eopXD edited the summary of this revision. (Show Details)
eopXD updated this revision to Diff 381873.Oct 25 2021, 1:16 AM
eopXD edited the summary of this revision. (Show Details)

Since parsing logic is unified, code of RISCVAsmParser can be reduced.

eopXD updated this revision to Diff 382225.Oct 26 2021, 1:52 AM

Fix test fail and clang-format error.

eopXD updated this revision to Diff 382250.Oct 26 2021, 3:34 AM

Update code and test case.

eopXD added a comment.EditedOct 26 2021, 3:34 AM

The test cases are modified because unifying the logic here shows the place where clang / llvm deal with target feature inconsistently.
I think it would be beneficial if we have them consistent.

  • Test cases with clang -cc1 originally don't do dependency check to target feature specified
    • This patch add target feature so that dependency checks can pass

Update:2021/10/31
This second part is canceled after Alex's comment below.

  • Originally clang driver's -march enforces version to be specified, while llvm allows .attribute arch to not specify version (and picks the default one)
    • This patch lets clang search for default version if no version is specified (so delete NOVERS test case in clang/test/Driver/riscv-arch.c
asb added a comment.EditedOct 28 2021, 5:57 AM

Thank you for the patch. This doesn't apply cleanly to current HEAD, could you please rebase?

I think the second part of this that you list, where the ISA extension version becomes optional is undesirable. We made the explicit choice of requiring the version string to be specified for experimental extensions in order to make it even clearer up-front that these are subject to change (and to allow people to catch easily when the supported ISA version has changed in a compiler update).

luke957 resigned from this revision.Oct 28 2021, 7:31 AM

So sorry for my bad herald script.

eopXD updated this revision to Diff 383607.Oct 30 2021, 10:53 AM

Address comment: Enforce user to specify version checks.

@asb Thank you for leaving comments for this patch.

eopXD updated this revision to Diff 383647.Oct 31 2021, 4:54 AM

Set ExperimentalExtensionVersionCheck=true for RISCVISAInfo::parseArchString in RISCVAsmParser.cpp

Add version numbers for test case in attribute-arch.s

eopXD updated this revision to Diff 383733.Nov 1 2021, 1:31 AM

rebase.

eopXD updated this revision to Diff 383775.Nov 1 2021, 4:39 AM

Rebase.

asb added a comment.Nov 5 2021, 4:09 AM

Add version numbers for test case in attribute-arch.s

Thanks for updating the patch. Why change this test case? I thought those lines were verifying that .attribute arch without a version number was accepted but the output file included a version number. I'll admit that's not fully consistent with requiring the version number explicitly on the command-line. If a behaviour change is desired here, it would be good to test the case where version numbers aren't specified.

I think for a patch like this, if it at all possible it would be best to do the refactoring in a way that doesn't alter behaviour and then follow-up with separate patches that change any other behaviour (if desired). Then we can review and discuss the refactoring and any functional changes separately, without one discussion blocking the other.

eopXD added a comment.EditedNov 5 2021, 8:06 AM

@asb Thanks for the reply.

To clarify the question, the 2 inconsistencies are:

  • Test cases with clang -cc1 originally don't do dependency check to target feature specified (handled by parseFeatures)
  • Clang driver's -march (handled by parseArchString) enforces version to be specified, while llvm allows .attribute arch to not specify version and picks the default one (handled by parseFeatures)

What this patch tries to do, letting the 2 actions rely on the same function call will mean to alter the behavior on one of them.
In my humble opinion, it is rather awkward to make this patch an NFC while letting the 2 actions call the same function.
Maybe we can first come to a conclusion on how do we unify and then implement them in this patch.

The main intentions of unifying them is that there will be some implications and dependency checks on the addition of zve and zvl,
so unifying the logics will make the addition have less code duplication.

eopXD edited reviewers, added: asb; removed: luke957.Nov 5 2021, 8:10 AM
eopXD added a comment.Nov 11 2021, 9:44 PM

ping, thank you.

asb added a comment.Nov 17 2021, 6:44 AM

OK, that reasoning makes sense. I think my only outstanding request would be to ensure there's some test coverage for the case of .attribute arch with an experimental extension without version info.

eopXD updated this revision to Diff 390187.Nov 28 2021, 1:04 AM
  • Update code (zfh have been added recently.
  • Added test case attribute-arch-invalid.s to show that experimental extensions need to specify the version explicitly.
asb accepted this revision.Dec 9 2021, 4:57 AM
This revision is now accepted and ready to land.Dec 9 2021, 4:57 AM
eopXD updated this revision to Diff 393181.Dec 9 2021, 8:39 AM

One last rebase before landing.