This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use RISCVISAInfo to parse arch string from ELF build attribute.
AbandonedPublic

Authored by kito-cheng on May 8 2022, 9:23 PM.

Details

Summary

ELFObjectFileBase::getRISCVFeatures using a handmade simple parser
to parse arch attribute, and that have long time no update, I think the
reasonble way to fix is using RISCVISAInfo, so that we can keep maintain
a unify infrastructure.

And there is an extra requirement for ELFObjectFileBase::getRISCVFeatures,
that might got unrecognized extensions, for example, the object is
compiled by GNU toolchain, and that might contain extensions which is
not supported yet by LLVM.

Diff Detail

Event Timeline

kito-cheng created this revision.May 8 2022, 9:23 PM
Herald added a reviewer: MaskRay. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
kito-cheng requested review of this revision.May 8 2022, 9:23 PM

Does this test case need to be updated? llvm/test/MC/RISCV/attribute-with-insts.s

Changes:

  • Add missing testcase...

@liaolucy

Does this test case need to be updated? llvm/test/MC/RISCV/attribute-with-insts.s

The testcase already has arch attribute, so assemble disassemble are work fine as past, the difference is disassembler using RISCVISAInfo to parse arch string from ELF attribute.

llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
37–38
NOTE: This update the testcase to fit the canonical order.

The testcase already has arch attribute, so assemble disassemble are work fine as past, the difference is disassembler using RISCVISAInfo to parse arch string from ELF attribute.

For example, does V extensions(.attribute arch, "xxxx_v1p0") need to be added to attribute-with-insts.s?

arichardson added inline comments.May 9 2022, 12:25 AM
llvm/include/llvm/Support/RISCVISAInfo.h
49

This name is quite confusing, maybe just IgnoreUnknown?

kito-cheng updated this revision to Diff 427994.May 9 2022, 1:06 AM

Changes:

  • Rename IgnoreUnknownOrError to IgnoreUnknown.
kito-cheng marked an inline comment as done.May 9 2022, 1:06 AM
kito-cheng added inline comments.
llvm/include/llvm/Support/RISCVISAInfo.h
49

Thanks!

jhenderson added inline comments.May 9 2022, 1:28 AM
llvm/lib/Object/ELFObjectFile.cpp
308–322
311–312

The final argument needs a comment too.

328–330

What does AddFeature take? Should Feature be a StringRef? If not, I'd still spell out the type rather than use auto.

Also, no need for braces for single-line for loops.

llvm/lib/Support/RISCVISAInfo.cpp
563

I don't know RISC-V at all, but is there any particular reason this is in the order it is? If not, I'd suggest changing it to alphabetical order.

kito-cheng marked 5 inline comments as done.

Changes:

  • Address @jhenderson's comment
    • Minor style fixing.
    • Refactor RISCVISAInfo::parseArchString, using isSupportedExtension rather than maintain SupportedStandardExtension.
kito-cheng added inline comments.May 11 2022, 8:30 AM
llvm/lib/Object/ELFObjectFile.cpp
328–330

What does AddFeature take? Should Feature be a StringRef?

StringRef, that should take StringRef and take care about the lifetime in my first impression, but I realized that actually store in a std::vector<std::string>[1], so I just pass std::string here.

[1] https://llvm.org/doxygen/SubtargetFeature_8h_source.html#l00184

llvm/lib/Support/RISCVISAInfo.cpp
563

That's part RISC-V standard, we called it canonical order of arch. string[1], but that remind me I should refactor that to using isSupportedExtension rather than maintain a magical string here.

[1] https://github.com/riscv/riscv-isa-manual/blob/master/src/naming.tex#L182

jhenderson added inline comments.May 11 2022, 11:43 PM
llvm/lib/Object/ELFObjectFile.cpp
328–330

Since AddFeature takes a StringRef, we should just pass one in, i.e. const std::string & -> StringRef. Lifetime isn't an issue here, so it doesn't matter which we use, but the LLVM guidelines are to use StringRef, I believe.

kito-cheng marked an inline comment as done.

Changes:

jhenderson added inline comments.May 13 2022, 7:27 AM
llvm/lib/Object/ELFObjectFile.cpp
329–330

This is what I meant.

Changes:

  • Address @jhenderson's comment, this time should be right :P
kito-cheng marked an inline comment as done.May 13 2022, 7:31 AM
kito-cheng added inline comments.
llvm/lib/Object/ELFObjectFile.cpp
329–330

I thought range based for should match the type of the source container, it's my first time to know this usage, thanks!

No more comments from me, but someone with RISCV knowledge should also review.

MaskRay added inline comments.May 16 2022, 12:50 PM
llvm/lib/Object/ELFObjectFile.cpp
315

This should be fixed.

kito-cheng abandoned this revision.Dec 8 2022, 8:35 AM
kito-cheng marked an inline comment as done.