This is an archive of the discontinued LLVM Phabricator instance.

[Xtensa 4/10] Add basic *td files with Xtensa architecture description.
ClosedPublic

Authored by andreisfr on Jul 16 2019, 3:21 PM.
Tokens
"Like" token, awarded by pilotniq.

Details

Summary

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.

Diff Detail

Event Timeline

andreisfr created this revision.Jul 16 2019, 3:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2019, 3:21 PM
arsenm added a subscriber: arsenm.Jul 16 2019, 3:24 PM
arsenm added inline comments.
llvm/lib/Target/Xtensa/XtensaRegisterInfo.td
41–46

Usually the register names and corresponding generated enums are capitalized

appcs added a reviewer: appcs.Jul 16 2019, 4:03 PM

Where is the Xtensa instruction set architecture (ISA) document on which this patch is based on?

andreisfr updated this revision to Diff 212684.Jul 31 2019, 3:51 PM

Register names are capitalized.

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 don’t think I saw an RFC for this target? Was there one I missed?

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

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 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.

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?

@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.

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?

@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).

andreisfr added a comment.EditedJan 17 2020, 4:07 AM

@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?

andreisfr updated this revision to Diff 242205.Feb 3 2020, 3:14 PM

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

@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 marked an inline comment as done.Feb 9 2020, 4:54 PM

@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.

https://0x04.net/~mwk/doc/xtensa.pdf

lattner removed a subscriber: lattner.Aug 29 2020, 9:19 PM
brainstorm added a comment.EditedJan 18 2021, 2:26 AM

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.

jscott added a subscriber: jscott.Jan 20 2021, 1:07 PM

@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.

andreisfr added a comment.EditedJan 24 2021, 5:14 PM

@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)?

@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 Yes, that sounds good.

aykevl added a comment.Mar 4 2021, 6:45 AM

@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

aykevl added a comment.EditedMar 4 2021, 4:31 PM

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.

@aykevl , I prepared new version of patches and I will update them in 1 day.

andreisfr updated this revision to Diff 328695.EditedMar 5 2021, 4:44 PM

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

aykevl added a comment.Mar 9 2021, 2:28 PM

@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.

If you think you meet those requirements, please re-send the RFC to the list, so we can discuss getting this added.

craig.topper added inline comments.
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.

andreisfr updated this revision to Diff 335949.Apr 7 2021, 4:40 PM

Correct instruction descriptions, format descriptions and instruction operands according to common style for *.td files.

andreisfr added inline comments.Apr 7 2021, 4:47 PM
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

@craig.topper , thank you very much for comments!

craig.topper added inline comments.Apr 8 2021, 3:01 PM
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.

andreisfr updated this revision to Diff 336425.Apr 9 2021, 6:09 AM

Corrected indentation, removed blank line

llvm/lib/Target/Xtensa/XtensaInstrFormats.td
167

Corrected

llvm/lib/Target/Xtensa/XtensaRegisterInfo.td
31

Corrected

lmb added a subscriber: lmb.May 31 2021, 3:01 AM
marbre added a subscriber: marbre.Aug 11 2021, 12:27 AM
ofen added a subscriber: ofen.Nov 8 2021, 1:36 PM

Who is needed to review and approve this patch?

Patch is updated according to LLVM upstream version.

bero added a subscriber: bero.Apr 14 2022, 1:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 1:59 PM
luojia added a subscriber: luojia.Apr 26 2022, 2:22 AM

What's the current state of this patch? :)

ofen removed a subscriber: ofen.Apr 26 2022, 2:38 AM

What's the current state of this patch? :)

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 :

  1. All 10 patches are updated according to the latest upstream changes . Patches 1-3 are approved.
  2. We have submitted an RFC to the mailing list https://lists.llvm.org/pipermail/llvm-dev/2021-March/149090.html .
  3. We have written the ISA documentation https://github.com/espressif/xtensa-isa-doc .
  4. Also we have a branch on Github with patches rebased to llvm-project main branch https://github.com/espressif/llvm-project/tree/main_xtensa .
saugustine requested changes to this revision.Aug 19 2022, 3:33 PM
saugustine added a subscriber: saugustine.

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
52

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
101

This is quite a bit more conservative than necessary. MEMW only serializes memory operations, it is fine to move arithmetic ops across it.

108

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).

115

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.

122

ISYNC synchronizes the instruction fetch unit against updates to the icache. Needs hasSideEffects set.

129

This synchronizes reading register fields out of instructions against WSR and XSR modifying the register window. Needs hasSideEffects set.

136

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.

This revision now requires changes to proceed.Aug 19 2022, 3:33 PM
andreisfr updated this revision to Diff 455441.Aug 24 2022, 5:56 PM

Corrected MEMW, EXTW, DSYNC, ESYNC, ISYNC and RSYNC instruction descriptions

andreisfr marked 6 inline comments as done.Aug 24 2022, 6:17 PM

@saugustine , thank you very much for your comments!

llvm/lib/Target/Xtensa/XtensaInstrFormats.td
52

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
101

Corrected

108

Corrected

115

Corrected

122

Corrected

129

Corrected

136

Corrected

saugustine accepted this revision.Aug 29 2022, 6:11 PM
This revision is now accepted and ready to land.Aug 29 2022, 6:11 PM
phosek added a subscriber: phosek.Sep 1 2022, 11:43 AM
andreisfr marked 6 inline comments as done.Oct 10 2022, 7:11 AM

@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.

barannikov88 added inline comments.
llvm/lib/Target/Xtensa/XtensaInstrFormats.td
218
  • IIRC SoftFail is no longer necessary after this patch (if you don't use this functionality, of course).
  • 'field' seems redundant, too (hasn't this keyword been deprecated?).
  • Do isCodeGenOnly instructions really need encoding bits?
andreisfr updated this revision to Diff 485249.Dec 25 2022, 4:28 PM

Added fixes according to comments

andreisfr added inline comments.Dec 25 2022, 4:29 PM
llvm/lib/Target/Xtensa/XtensaInstrFormats.td
218

Thank you for comments, I removed redundant code.

barannikov88 accepted this revision.Dec 25 2022, 5:29 PM
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.