This is an archive of the discontinued LLVM Phabricator instance.

[Xtensa 9/10] Add basic support of Xtensa disassembler.
ClosedPublic

Authored by andreisfr on Jul 16 2019, 3:29 PM.

Diff Detail

Event Timeline

andreisfr created this revision.Jul 16 2019, 3:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2019, 3:29 PM
andreisfr updated this revision to Diff 212696.Jul 31 2019, 4:06 PM

Register names are capitalized.

MaskRay added inline comments.
llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp
29

using is more common in newer code. This doesn't have to copy from other targets.

andreisfr updated this revision to Diff 242219.Feb 3 2020, 3:19 PM

Patch is updated according to latest upstream version. Updated licenses.

andreisfr marked an inline comment as done.Feb 9 2020, 4:54 PM
andreisfr updated this revision to Diff 328701.EditedMar 5 2021, 4:47 PM

Patch is updated according to LLVM upstream version and latest Xtensa backend version.

andreisfr updated this revision to Diff 335959.Apr 7 2021, 4:56 PM

Correct instruction descriptions, format descriptions and instruction operands according to common style for *.td files. The llvm_unreachable is substituted to report_fatal_error.

Patch is updated according to LLVM upstream version.

bero added a subscriber: bero.Apr 14 2022, 2:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 2:00 PM
andreisfr updated this revision to Diff 425078.Apr 25 2022, 5:18 PM

Patch is updated according to LLVM upstream version

Patch is updated according to LLVM upstream version

This is largely mechanical, so mostly looks good with a minor nit.

Disassembly is likely to run into issues with invalid instructions in the stream because the llvm disassembler doesn't honor .xt.insn section notes. For example, the nop padding from D64831 is going to trip this up if it runs into a single-byte pad, or the two-byte density nops, for that matter. This is one of the caveats of Xtensa's 2 and 3 byte instructions when you need to pad a single byte--there isn't any valid instruction to do that.

The alternative would be to never pad with illegal instructions. On a density machine, if you need a single-byte of padding, you can five-bytes (fetch width + remainder). On a non-density machine, it gets more complicated.

Still, this is not exactly a correctness issue, but it will make using this disassembler for real work tricky. Honoring .xt.insn sections is likely beyond the scope here.

Worse, the gnu assembler won't be able to properly disassemble these situations either, as this implementation doesn't generate .xt.insn sections.

I suppose people who care can use the gnu assembler and disassembler rather than llvm's built in version.

llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp
172

this only reads three bytes, does it not? And no need to comment about the endianness--it isn't supported.

phosek added a subscriber: phosek.Sep 1 2022, 11:44 AM
tpambor added a subscriber: tpambor.Sep 4 2022, 3:07 AM
andreisfr updated this revision to Diff 461121.Sep 18 2022, 6:46 PM

Corrected comment. The "array_lengthof" changed to "std::size".

llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp
172

Corrected

andreisfr added a comment.EditedOct 5 2022, 4:01 AM

@saugustine , we added to the our plans implementation of the ".xt.insn" section. Is it suitable solution to resolve the issue with "nop" operation in this patch?

JKRhb added a subscriber: JKRhb.Oct 9 2022, 2:30 PM
saugustine accepted this revision.Dec 13 2022, 10:41 AM
This revision is now accepted and ready to land.Dec 13 2022, 10:41 AM
barannikov88 added inline comments.
llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp
205

This should probably be done inside readInstruction24.

andreisfr updated this revision to Diff 485254.Dec 25 2022, 4:37 PM

Added fixes according to comments

llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp
205

Fixed

barannikov88 accepted this revision.Dec 25 2022, 6:16 PM
barannikov88 added inline comments.
llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp
179

(cosmetic) If you have only two bytes in the buffer, this method will be called twice, fail twice, and <unknown> will be printed twice, which is probably not what you want.
Setting Size = Bytes.size() avoids the issue.

This revision was landed with ongoing or failed builds.Dec 26 2022, 4:39 AM
This revision was automatically updated to reflect the committed changes.