[PATCH] D153008: [RISCV] Allow slash-star comments in instruction operands
Abel Bernabeu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 15 06:58:03 PDT 2023
abel-bernabeu updated this revision to Diff 531735.
abel-bernabeu added a comment.
[RISCV] Allow slash-star comments in instruction operands
It has been reported by one of Esperanto's customers that slash-start
comments ("/*") within inline assembly were only allowed before the
first instruction operand or at the end of the lines. Those comments
were, however, not allowed when interleaved within the operands.
An example follows:
unsigned long int dst;
__asm__ __volatile__(
"li /* this was fine */ %[dst], /* this was NOT fine */ 0x1234\n"
"add zero, %[dst], %[dst]\n"
: [ dst ] "=r"(dst)
:
:);
A code review of the top level parser (AsmParser class) showed that
when comments were placed before the instruction operand or at end of
a line, then they were gracefully handled irrespective of the backend.
When the comments were interleaved within the instruction operands it
was the backend's responsibility to handle the comments.
RISC-V's backend did not handle the comments in any way.
Beyond the obvious solution of explicitly handling the comments within
the RISC-V backend, another, easier to maintain solution was suggested
by Sergei Barannikov in a Discourse discussion thread:
https://discourse.llvm.org/t/interleaving-several-c-style-comments-in-the-same-inline-assembly-line/71353/8
In summary, all backends, including the RISC-V's, should switch
from getLexer().Lex() to getParser().Lex() in their ParseInstruction
implementation.
The getLexer().Lex() approach relies on the user to explicitly handle
the comments, whereas the suggested getParser().Lex() alternive already
handles the comments in the same way as done for non-target-specific
assembly directives.
Here we just do the RISC-V work. Other backends should also do their own
review.
In addition to Sergei Barannikov, I would also we thank David Spikett
from Arm's community for pointing out where to start looking within the
LLVM code base, and also the patch reviewers.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153008/new/
https://reviews.llvm.org/D153008
Files:
clang/test/CodeGen/RISCV/riscv-inline-asm-gcc-commenting.c
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153008.531735.patch
Type: text/x-patch
Size: 6078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230615/b470a68e/attachment.bin>
More information about the llvm-commits
mailing list