This is an archive of the discontinued LLVM Phabricator instance.

RISCV: honour `.option relax` in assembly
AbandonedPublic

Authored by compnerd on May 26 2021, 8:48 AM.

Details

Reviewers
asb
jrtc27
Summary

We would lex the .option relax and effectively drop the request on the
floor. This is due to the fact that the configuration was set in the
assembler state, but the MC system only consults the static subtarget
information (and an additional bit?). Wire up the ASMStreamer to the
additional bit to ensure that the request is honoured.

It is important to note that the relaxation option is applied to the
entire file. As a result, the additional cases test that the rest of
the file is also processed accordingly.

Diff Detail

Event Timeline

compnerd created this revision.May 26 2021, 8:48 AM
compnerd requested review of this revision.May 26 2021, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2021, 8:48 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

I don't understand the diff rendering on differential. The change is literally the 3 lines being added to RISCVTargetELFStreamer::emitDirectiveOptionRelax. The raw diff does not show any changes to the other lines around it.

jrtc27 requested changes to this revision.May 26 2021, 9:00 AM

Shouldn't this be covered by option-relax.s already though? Is that test wrong? Is it specifically because of the .option push? If so, just shove a .option push/.option pop pair around the whole file. This also feels like the wrong place to fix this; we already handle it for instructions in RISCVAsmParser::ParseInstruction, and that was a deliberate choice to make it lazy. In fact, I don't think there is a bug at all? If there are no instructions emitted subject to relaxation, the bit isn't set, because it's unnecessary, and if there are instructions emitted subject to relaxation, we set the bit. Am I missing something?

llvm/test/MC/RISCV/scoped-relaxation.s
2

Fix style to match other tests and remove redundant options. # is the canonical comment prefix for RISC-V, not //.

4

Don't indent any of these, it just makes the test look ugly.

This revision now requires changes to proceed.May 26 2021, 9:00 AM
MaskRay added inline comments.May 26 2021, 11:55 AM
llvm/test/MC/RISCV/scoped-relaxation.s
10

For llvm-readobj -r, in many cases I suggest that the { and } brace lines are checked as well to ensure the relocations are fully specified.

Shouldn't this be covered by option-relax.s already though? Is that test wrong?

It isn't; the test doesn't cover any non-local symbols, so everything just happens to work out. I can certainly merge this into that file if you prefer.

compnerd marked 2 inline comments as done.Jun 2 2021, 9:59 AM
compnerd added inline comments.
llvm/test/MC/RISCV/scoped-relaxation.s
4

I think that we can disagree then. I think that it is far more legible than everything being 0-column aligned. FWIW, most of the other backends do use the indentation (particularly the ones that I've worked with in LLVM in the past - ARM, ARM64, X86, and by extension X86_64).

compnerd updated this revision to Diff 349309.Jun 2 2021, 10:01 AM
compnerd marked an inline comment as done.
MaskRay added inline comments.Jun 2 2021, 10:07 AM
llvm/test/MC/RISCV/scoped-relaxation.s
4

Personally I keep .globl/labels/etc at 0-column (top-level stuff) and .long/.word/etc at 2-column (function-level stuff).

I would suggest few more line on testcase:

.option push
.option relax
call function #check R_RISCV_RELAX is here
.option pop
.option push
.option norelax #check no R_RISCV_RELAX
call function
.option pop
compnerd planned changes to this revision.Jun 4 2021, 3:09 PM
compnerd abandoned this revision.Jun 17 2021, 11:31 AM