Issues building/using the AVR backend


I’m looking for some guidance in adding/using the AVR LLVM backend with Clang. I don’t know if this is more appropriate for the llvm-dev list, so feel free to point me that way if this has nothing to do with Clang.

My understanding is that the latest LLVM trunk supports the AVR backend, so I checked out the source and tried building it. I stumbled across a few posts online mentioning that the list of LLVM targets is specified in the top-level CMakeLists file. AVR isn’t in the list on the trunk, so I added it and ran CMake with -DLLVM_TARGETS_TO_BUILD=AVR. This works and prints out ‘-- Targetting AVR’, so it certainly looks like this is working. During compilation, I also seem a promising list of targets being built — AVRCommonTableGen, LLVMAVRCodeGen, etc.

Is this all it takes to build in the backend? I’ve tried using it but haven’t had any luck. I’ll give a few examples.

clang --target=avr main.c -o main.o

error: unable to create target: ‘No available targets are compatible with this triple.’

1 error generated.

clang --target=avx main.c -o main.o

error: unknown target triple ‘avx’, please use -triple or -arch

My dummy target generates a different error than when I pass in avr, so again, it looks like LLVM/Clang has some understanding that AVR targets are supported.

I understand that before being integrated into the trunk, the backend was implemented as the ‘avr-llvm’ project. Looking at its wiki, the guide says to pass the ‘-mmcu’ flag to Clang. This doesn’t seem to work either

clang --target=avr main.c -o main.o -mmcu=atmega1284p

clang-5.0: error: unknown argument: ‘-mmcu=atmega1284p’

Also, this may be irrelevant, but the string ‘mmcu’ doesn’t appear anywhere in the Targets/AVR source directory. This makes me think that the calling convention may have changed.

Finally, my output from ‘llc --version’ does not show ‘avr’ as a registered target. This seems like it is very important, but again, I don’t really know.

Any help would be appreciated. Does it look like I configured the build properly with CMake? Am I passing the wrong arguments to Clang? Is the AVR backend not fully integrated?