Add initial Xtensa.td file with target machine description. Add XtensaInstrInfo.td,
currently describe just susbet of Core Instructions like ALU, Processor control,
memory barrier and some move instructions. Add descriptions of the instructions
formats(XtensaInstrInfo.td) and some immediate instruction operands(XtensaOperands.td).
Add General Registers and Special Registers classes.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Target/Xtensa/XtensaRegisterInfo.td | ||
---|---|---|
41–46 | Usually the register names and corresponding generated enums are capitalized |
Where is the Xtensa instruction set architecture (ISA) document on which this patch is based on?
As for Xtensa instruction set architecture (ISA) document , currently public ISA description mainly available in opensource projects like gcc/qemu/binutils:
https://github.com/gcc-mirror/gcc/tree/master/gcc/config/xtensa
https://github.com/qemu/qemu/blob/master/target/xtensa/translate.c
https://github.com/bminor/binutils-gdb/blob/master/bfd/xtensa-modules.c
I sent RFC to LLVM community on 6 March http://lists.llvm.org/pipermail/llvm-dev/2019-March/130796.html
So the only documentation is the existing implementations?
To me personally that does not sound like there is documentation..
Doing a websearch for "xtensa isa", I do see that documentation does seem to exist: https://github.com/eerimoq/hardware-reference/blob/master/esp32/xtensa%20Instruction%20Set%20Architecture%20(ISA)%20Reference%20Manual.pdf.
It would sure be nice if it was hosted in a more official location, though.
I do not think there is a reason why the Xtensa architecture shouldn't be included in LLVM. As a comparison, there is also the proprietary (Google) Lanai architecture which was added at a time when there was little public information on it and to this time nobody can actually buy Lanai hardware (there is only a simulator). As a comparison, Xtensa has easy to get hardware (in the form of the ESP8266/ESP32) and is already supported in GCC/binutils.
Looking back at the email thread, there were very few responses. I wonder what should be done next?
Tagging Chris just in case: @lattner
I'd note that Lanai did publish a set of ISA docs as part of upstreaming the llvm backend.
Having something like that perhaps doesn't need to be a hard-blocker, but I'd love to see a real response from the xtensa folks, since AFAICT it looks as if like there *IS* ISA documentation, just perhaps not -- officially -- publicly available. It would make things much easier to understand if xtensa published what they had. Without that, nobody else can really review or understand the backend.
I'd note that Lanai did publish a set of ISA docs as part of upstreaming the llvm backend.
Having something like that perhaps doesn't need to be a hard-blocker, but I'd love to see a real response from the xtensa folks, since AFAICT it looks as if like there *IS* ISA documentation, just perhaps not -- officially -- publicly available. It would make things much easier to understand if xtensa published what they had. Without that, nobody else can really review or understand the backend.
@jyknight , as I'm understood, Cadence doesn;t want to publish Xtensa ISA. But it seems that documentation from the link that you provided is quite actual, probably it was published when Xtensa was owned by Tensilica. Also, the code can be reviewed by people from companies that use Xtensa IP in their chips.
BTW there is also an ARC backend (from Synopsys), and I have not found any public documentation with ARC ISA, so probably encoding of ARC instructions also could be verified only by Synopsys engineers.
Also we could prepare summary about Xtensa ISA based on public resources like GCC, Binutils, QEMU with quality enough for code review. What do you think?
That seems really silly -- why wouldn't someone want all users of their CPUs to be able to easily access the ISA docs. Oh well.
Anyways, are there some folks who know LLVM and do have access to the official documentation who can help review the patches? (Maybe asking on the mailing list thread would be useful.)
BTW there is also an ARC backend (from Synopsys), and I have not found any public documentation with ARC ISA, so probably encoding of ARC instructions also could be verified only by Synopsys engineers.
Also we could prepare summary about Xtensa ISA based on public resources like GCC, Binutils, QEMU with quality enough for code review. What do you think?
I think a short summary of the general characteristics of the CPU/ISA would be useful. I do not think that it would be a productive use of time to attempt to reverse-engineer/rewrite an entire ISA doc -- having such a reverse-engineered and possibly incorrect or outdated doc might even be worse than not having it. But I do not think lack of public documentation should be a blocker for inclusion, especially if there are folks who do have access to the privately-available documentation who can help review.
@andreisfr @jyknight @ivanbaev Ping? Are there any news concerning these pull requests?
From my point of view, this is waiting for the submitter to follow up (or someone may take over).
@codehippo, @jyknight, @ivanbaev , we still active develop and improve Xtensa backend, for example this is recent version https://github.com/espressif/llvm-project/tree/xtensa_release_9.x currently we maintain mainstream version and we plan to publish one based on release 10. Current review is paused on *.td files with Xtensa ISA description after the question about ISA documentation, we have been tried to find a way how to help reviewers to aprove this code. We interested to integrate Xtensa backend to upstream and make it available to LLVM community, so we are going to prepare Xtensa ISA description based on opensource projects like binutils, gcc etc. It seems to be the only way to continue review process. What do you think?
@jyknight, @ivanbaev , currently is available Xtensa backend based on latest 9.0.1 release https://github.com/espressif/llvm-project/tree/xtensa_release_9.0.1
@appcs Do you perhaps have access to the ISA documentation so you can review these patches?
@andreisfr Has any progress been made on the reverse-engineered Xtensa ISA based on the open-source projects like gcc and binutils?
Not sure how relevant it is, but I found this PDF which seems to be some documentation for the ISA.
Hello LLVM,
I own an Xtensa ISA document from 2015 and I can confirm that the 2010 ISA document linked above (https://0x04.net/~mwk/doc/xtensa.pdf as @philip-peterson points out) is sufficient to proceed with this review since the changes between those two documents are not that substantial on a first pass. So please, could you take that 0x04.net as authoritative source for this review?
I'd be happy to help review corner cases as they pop up if need be, @ivanbaev @jyknight.
Please bear with me LLVM maintainers since I've never upstreamed a compiler backend, but is there any other document than https://www.llvm.org/docs/WritingAnLLVMBackend.html which outlines the comformance testing required to get this xtensa work in-tree? I would like to see this backend supported in LLVM after all the effort that @andreisfr and others have put into this.
There is also this document: https://llvm.org/docs/DeveloperPolicy.html#adding-a-new-target
@andreisfr I don't seen any major issues being raised with this backend. It would be great if there was a public official ISA document, but I don't think the lack of one is a blocker. Please make a last check of the reviews in phabricato to see if there are any outstanding issues. Then, I would recommend you take a look at the documentation @tonic posted. Specifically the 5 bullet points under the "The basic rules for a back-end to be upstreamed in experimental mode are:" header. If you think you meet those requirements, please re-send the RFC to the list, so we can discuss getting this added.
@brainstorm , @tonic , @tstellar , thank you very much for your help!
I support and improve Xtensa backend now, current version of the backend is rebased on release 11.0.0 https://github.com/espressif/llvm-project/tree/xtensa_release_11.0.0 .
@tstellar , so I can just update these 10 patches according to latest changes in LLVM, add myself as code owner in the first patch and send patches again to list (I will recheck outstanding issues)?
@andreisfr any update on this?
It would be great if you could update these patches and send a new RFC to llvm-dev, like you did here: https://lists.llvm.org/pipermail/llvm-dev/2019-March/130796.html
Also, there is an emulator here: https://github.com/espressif/qemu/wiki
I have successfully used it in the past. Noting it here as it can make backend review/development easier for those who don't have the hardware.
Patch is updated according to LLVM upstream version and latest Xtensa backend version.
@andreisfr awesome! Thanks a lot!
Can you please also write a new RFC and send it to llvm-dev like @tstellar proposed? An RFC is the next step in getting this backend accepted.
llvm/lib/Target/Xtensa/Xtensa.td | ||
---|---|---|
2 | Please limit line length to 80 characters | |
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
2 | Please limit line length to 80 characters | |
15 | I think the prevailing style in LLVM has the open curly brace at the end of the previous line. | |
32 | It might just be me, but I find this lining the XtensaInst up with template parameters hard to read. I think a common style is to put at the start of the line with only a small indentation. For example class PseudoI<dag oops, dag iops, list<dag> pattern> : X86Inst<0, Pseudo, NoImm, oops, iops, ""> { let Pattern = pattern; } | |
llvm/lib/Target/Xtensa/XtensaOperands.td | ||
2 | This line seems shorter than 80 characters. |
Correct instruction descriptions, format descriptions and instruction operands according to common style for *.td files.
llvm/lib/Target/Xtensa/Xtensa.td | ||
---|---|---|
2 | Corrected | |
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
2 | Corrected | |
15 | Corrected for instruction descriptions, format descriptions and instruction operands. | |
32 | @craig.topper , I corrected instruction formats and instruction descriptions, do you think that this code now in common style or it must be corrected bit more? | |
llvm/lib/Target/Xtensa/XtensaOperands.td | ||
2 | Corrected |
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
---|---|---|
32 | I think this looks better. Unfortunately, we don't have a formatting tool for tablegen and no rules are written down. I think this is good enough. | |
167 | Drop the second blank line? | |
llvm/lib/Target/Xtensa/XtensaRegisterInfo.td | ||
31 | This is overindented relative to the style of the rest of the file. |
HI @luojia, thank you for your interest to the Xtensa backend.
Currently, probably all suggestions in comments for this patch were implemented. If you can help with further reviewing or approving this patch that would be great.
Brief status of the whole series of the Xtensa backend patches :
- All 10 patches are updated according to the latest upstream changes . Patches 1-3 are approved.
- We have submitted an RFC to the mailing list https://lists.llvm.org/pipermail/llvm-dev/2021-March/149090.html .
- We have written the ISA documentation https://github.com/espressif/xtensa-isa-doc .
- Also we have a branch on Github with patches rebased to llvm-project main branch https://github.com/espressif/llvm-project/tree/main_xtensa .
I have access to an up-to-date copy of the isa book and can review these for technical correctness. I'm less familiar with style issues.
I have checked the bitfields, encodings, and field names. They are all correct.
Some comments below, especially on the xSYNC instructions. Nothing too serious, but they do have side effects of one form or another. Typically a compiler wouldn't generate them unless as part of a larger hard-coded, unsplittable block, but if they are present, they ought to be correct.
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
---|---|---|
53 | These fields are reverse order in big endian versions of the core. Is the ESP32 implementation of Xtensa always little endian? It would be nice to handle both variants, but that isn't a block for this patch. | |
llvm/lib/Target/Xtensa/XtensaInstrInfo.td | ||
102 | This is quite a bit more conservative than necessary. MEMW only serializes memory operations, it is fine to move arithmetic ops across it. | |
109 | This instruction is a superset of MEMW and serializes all externally visible operations. hasSideEffects is necessary on this one (at least in a base ISA implementation). | |
116 | DSYNC is the least intrusive processor-state sync instruction, used to serialize loads and stores against WSR and XSR instructions that may update the page table. It could be modeled quite similarly to MEMW, but with a more complete memory-barrier model, it should include side effects. | |
123 | ISYNC synchronizes the instruction fetch unit against updates to the icache. Needs hasSideEffects set. | |
130 | This synchronizes reading register fields out of instructions against WSR and XSR modifying the register window. Needs hasSideEffects set. | |
137 | This is quite similar to RSYNC, but synchronizes the exact read from the register window, rather than the fields out of the instruction. Needs hasSideEffects set. |
@saugustine , thank you very much for your comments!
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
---|---|---|
53 | Yes, the ESP32 implementation is always little endian, and I didn't observed any public available big endian implementations. So, initial idea was to implement just little endian at first and maybe implement support of the big endian in future. | |
llvm/lib/Target/Xtensa/XtensaInstrInfo.td | ||
102 | Corrected | |
109 | Corrected | |
116 | Corrected | |
123 | Corrected | |
130 | Corrected | |
137 | Corrected |
@aykevl , @jyknight , @ivanbaev , I have a good news about Xtensa ISA documentation. Cadence makes documentation publicly available https://www.cadence.com/content/dam/cadence-www/global/en_US/documents/tools/ip/tensilica-ip/isa-summary.pdf
What is the current state of this patch? As the Debian maintainer of ath9k_htc, the flagship libre wireless firmware for USB adapters, I eagerly wait for this to be merged so that I may begin exploring using LLVM to build the firmware, which is currently a rather painful process with GCC.
Hi everyone. Since this has been accepted for some time now, we're planning to commit this on Monday (December 16th). Please let us know if there is anything else we should address.
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
---|---|---|
218 |
|
llvm/lib/Target/Xtensa/XtensaInstrFormats.td | ||
---|---|---|
218 | Thank you for comments, I removed redundant code. |
Please limit line length to 80 characters