llvm-abi is a library that generates ABI-compliant LLVM IR. Hence this tackles a problem facing any LLVM front-end that wants to call or be called from C functions – this is a lot of front-ends!

This library was announced and discussed on the LLVM mailing lists.

Why is this needed?

LLVM IR doesn’t currently have any way for representing language type information, however platform ABIs are typically expressed in terms of source language types. This means backends don’t have all the available information for generating ABI-correct calls/returns so it’s up to frontends to emit code that provides the necessary information to the backend.

Unfortunately this task is quite involved and target-specific, hence this library has been created to handle this and abstract away the details.

What about other front-ends?

Up to now each LLVM front-end has re-implemented this functionality for its own use. Naturally Clang (the LLVM based C and C++ compiler) has the most complete/correct ABI code generation, whereas other front-ends have their implementations of varying quality determined by the available effort.

This situation is not ideal because in general all the front-ends are trying to do the same thing. llvm-abi is a way for front-ends to work together to substantially reduce development effort and improve front-end quality by sharing code.

What about Clang’s ABI code?

Currently llvm-abi has its own implementation of ABI compliance of which substantial portions have been pulled from Clang. Following recommendations on the LLVM mailing list the plan is that Clang itself will be re-factored to expose its own implementation of ABI-compliant code generation. The idea is then to modify the llvm-abi implementation to use Clang. Front-ends can therefore start using the llvm-abi library now and automatically benefit from this code sharing later.