avr-llvm / llvm

[MERGED UPSTREAM] AVR backend for the LLVM compiler library
220 stars 21 forks source link

Add atomics support #211

Closed dylanmckay closed 8 years ago

dylanmckay commented 8 years ago

This PR adds atomics support to AVR.

Still need to implement

Ideally we should use the AVR RMW instructions (XCH, etc) when we can. Not a priority though because they aren't well supported.

Fixes #197.

dylanmckay commented 8 years ago

@rjordans did you want to review this?

rjordans commented 8 years ago

Sure no problem, I was mainly trying to follow how this would be implemented and figured that I could just as well give some suggestions whenever I spot things. I hope you didn't mind.

Anyway, I guess you missed my last comment but from looking at the LLVM language reference it seems that the atomicrmw operations require a write-back of the new value as well. It seems like you miss that in the currently generated code. Other than that it looks really nice now.

dylanmckay commented 8 years ago

Suggestions and feedback are always appreciated :) I haven't worked with atomics much either so anything is useful.

Don't forget to store the result back to %foo though (see http://llvm.org/docs/LangRef.html#atomicrmw-instruction)

I didn't notice that before, nice catch!

dylanmckay commented 8 years ago

The atomic RMW instructions now store the value back to the original pointer.

dylanmckay commented 8 years ago

Have also rebased the branch so it's a bit cleaner.