Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc + avr = lovelove back again #139

Merged
merged 2 commits into from
May 8, 2022

Conversation

Patryk27
Copy link

@Patryk27 Patryk27 commented May 8, 2022

This merge request contains two commits cherry-picked from LLVM's main branch that solve the infamous LLVM ERROR: Not supported instr problem¹, making rustc able to compile for AVR back again 🙂

At the moment people wanting to play with Rust + AVR are being forced to use the, uhm, mature version of nightly-2021-01-07 that doesn't crash with Not supported instr, but contains a multitude of codegen bugs that have been since fixed in LLVM (e.g. rust-lang/rust#79889 should Just Work ™️ now, but people can't really test it if they are still using the older compiler).

Checks

I've checked the code by compiling rustc locally and simavr-ing a few examples from https://github.com/Rahix/avr-hal/tree/5d757696e338104622a0f89c51020b718bf48b62/examples/arduino-uno - everything seems to be working correctly.

I'm also developing a bit more complex AVR application (firmware? 🙃) myself, and I haven't noticed any compiler bugs, including when running the code on an actual Atmega328p.

¹ rust-lang/rust#82104, rust-lang/rust#83633

Patryk27 added 2 commits May 6, 2022 17:58
This commit contains a refactoring that merges AVRRelaxMemOperations
into AVRExpandPseudoInsts, so that we have a single place in code that
expands the STDWPtrQRr opcode.

Seizing the day, I've also fixed a couple of potential bugs with our
previous implementation (e.g. when the destination register was killed,
the previous implementation would try to .addDef() that killed
register, crashing LLVM in the process - that's fixed now, as proved by
the test).

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D122533
Currently, STDSPQRr and STDWSPQRr are expanded only during
AVRFrameLowering - this means that if any of those instructions happen
to appear _outside_ of the typical FrameSetup / FrameDestroy
context, they wouldn't get substituted, eventually leading to a crash:

```
LLVM ERROR: Not supported instr: <MCInst XXX <MCOperand Reg:1>
<MCOperand Imm:15> <MCOperand Reg:53>>
```

This commit fixes this issue by moving expansion of those two opcodes
into AVRExpandPseudo.

This bug was originally discovered due to the Rust compiler_builtins
library. Its 0.1.37 release contained a 128-bit software
division/remainder routine that exercised this buggy branch in the code.

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D123528
@Patryk27
Copy link
Author

Patryk27 commented May 8, 2022

cc @nikic

@nikic nikic merged commit 9a46e28 into rust-lang:rustc/14.0-2022-03-22 May 8, 2022
@Patryk27 Patryk27 deleted the avr-fixes branch May 8, 2022 16:13
Patryk27 added a commit to Patryk27/rust that referenced this pull request May 9, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2022
Upgrade llvm-project (rustc + avr = lovelove back again!)

See:
rust-lang/llvm-project#139

tl;dr:
- closes rust-lang#83633,
- closes rust-lang#82104,
- closes rust-lang#79889,
- closes rust-lang/compiler-builtins#400.

🙂
@agausmann
Copy link

I've been using these patches in a custom Rust+LLVM build for a while now, and very happy with it! Glad to see them merged finally; and many thanks @Patryk27 for your efforts ❤️

vext01 pushed a commit to vext01/llvm-project that referenced this pull request Apr 25, 2024
Serialise the successor block of unconditional branches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants