This is an archive of the discontinued LLVM Phabricator instance.

[RISCVAsmParser] Allow a SymbolRef operand to be a complex expression
ClosedPublic

Authored by MaskRay on Nov 29 2020, 8:53 PM.

Details

Summary

So that instructions like lla a5, (0xFF + end) - 4 (supported by GNU as) can
be parsed.

Add a missing test that an operand like foo + foo is not allowed.

Diff Detail

Event Timeline

MaskRay created this revision.Nov 29 2020, 8:53 PM
MaskRay requested review of this revision.Nov 29 2020, 8:53 PM
jrtc27 added inline comments.Nov 29 2020, 10:56 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1862

Should we not be passing the assembler pointer? I don't remember when exactly RISC-V needs it, but RISC-V is pickier due to supporting linker relaxation.

MaskRay marked an inline comment as done.Nov 30 2020, 10:31 AM
MaskRay added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1862

We don't need it here. Passing the pointer can enable more aggressive constant folding, but this appears to be fine for now.

jrtc27 added inline comments.Nov 30 2020, 10:34 AM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1862

Then we might as well? It's lying around in the target streamer's streamer (maybe elsewhere is more accessible too, this area of the MC layer gets a bit twisty-turny-maze).

MaskRay marked 2 inline comments as done.Nov 30 2020, 3:40 PM
MaskRay added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1862

We can't provide it. MCAsmLayout is constructed in MCAssembler::Finish, a very late stage (and only when MCObjectStreamer is used). The AsmParser code should work for both -filetype=asm and -filetype=obj.

The simplification here makes sense. If we find it overly restrictive in the future, we can consider deleting it (most other targets don't have such rigid checks - but the diagnostics will become worse " operand must be a bare symbol name" -> something in the relocation emission stage

MaskRay marked an inline comment as done.Dec 1 2020, 3:18 PM
jrtc27 accepted this revision.Dec 1 2020, 3:22 PM
jrtc27 added inline comments.
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1862

Well, if you use getAssemblerPtr() then you'd get back nullptr in those cases and fall back on the current behaviour, but there's also something to be said for consistency between the different ways this code can end up being called. I don't feel strongly about it, I just thought it was a nice to have.

This revision is now accepted and ready to land.Dec 1 2020, 3:22 PM
MaskRay added inline comments.Dec 1 2020, 4:04 PM
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
1862

classifySymbolRef is a static method:) I'll lean not to use getAssemblerPtr then.