Background
- builtins library from compiler-rt has portable default implementations written in C for all its LibCalls
- those implementations can be replaced by potentially much efficient target-specific ones when appropriate
- ideally, one should be able to start with all-default implementations ASAP when adding support for a new target, and then gradually improve it
Problem statement
- some targets have special requirements on LibCalls:
- name aliases (see existing ARM-specific aliases, MSP430 requires some as well)
- seemingly arbitrarily chosen calling conventions (see Section 6.3 of MSP430 EABI document). While they are probably justified by implementation specifics, it is hard to deduce the required convention merely from the signature (harder than just "special iff is LibCall and has two 64-bit arguments")
- the default implementation (that potentially is already quite elaborate) may perfectly fit all the requirements apart from those tiny configuration details
- it is worth not to force target implementations to diverge from the upstream ones just to account for such tiny details
- on the other hand, it is worth to not clobber the generic implementation with a bunch of target-specific defines
- bonus point: still catching as much errors at compile-time as possible
This proposal
This RFC includes an example implementation.
- + all adjustments listed above (calling conventions, name aliases) will be contained inside a single target specific header and a couple of lines in int_lib.h that conditionally #include that header
- + the default LibCall implementations will have O(1) customization-related code per file irrespective of how many targets perform some customizations
- - has large patch size
- + is by design a one-time refactoring simplifying adding new targets in the future
- + can already help factoring out the existing ARM-specific name aliases
- most of the changes was performed automatically by sed, so they (and their corresponding scripts) can be reviewed separately while spending most of the time on manual changes
- - has a shell script that may need re-running from time to time
- it is not required to have bash on every system that will just compile LLVM since the resulting header is expected to be committed to the repository
- there already exist some scripts under compiler-rt/utils that generate some headers for NetBSD
- - there is a possibility that someday someone will forget to re-run it
- + most probably, the only cases when running it is actually required are
- adding some new LibCall
- changing the set of parameters (now, there exist two: "calling convention" = "misc attributes" and "name aliases" = "misc footer")
- + it seems to have much simpler requirements on how to run it than some of those NetBSD-related scripts :)
- - more real-world mistake would probably be to make a simple change (such as adding one another generic source file) and updating the autogenerated header manually because it was so trivial change, so when the script will be eventually re-run, there would be some unexpected changes
- + because the script has very weak assumptions on how it should be run, we can just have a test (that requires bash) that ensures that the committed script and the committed header match (something like checking code style by auto-formatting and checking that nothing changes)
- + when something was made wrong, chances are high it would be caught early
- declaring a new LibCall via DECLARE_LIBCALL macro without updating the script immediately triggers a compilation error
- - on the target implementation side, there are no safety nets, so one can easily mistype a LibCall name in a statement like #define AUX_DECLS__ashldi3 ... that would be silently ignored in this approach
- there is a chance this would be caught by target-specific tests and debugged and fixed early by the same person who is implementing that target's support (at least, when changing calling convention)
- the most care should probably be taken when reviewing this particular initial implementation, as I have to "import" the existing ARM-specific aliases
clang-format: please reformat the code