[cfe-dev] [RFC] [compiler-rt][builtins] Make the default LibCall implementations more customizable

Anatoly Trosinenko via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 21 06:19:02 PDT 2020


Hello,

When working with the builtins library from compiler-rt, turned out some trivial customization points may be useful.

# Background

* The 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 [1]). 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 can probably be quite elaborate) may perfectly fit all the requirements except for 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

# Implementation

Here is an example implementation: https://reviews.llvm.org/D84636. It uses preprocessor macro and a header that is auto-generated by a shell script. The two customization points it introduces are per-LibCall `__attribute__`s (calling conventions, etc.) and generic source file footers (name aliases can be placed there).

[1] MSP430 EABI: https://www.ti.com/lit/an/slaa534a/slaa534a.pdf

Best regards,
Anatoly Trosinenko


More information about the cfe-dev mailing list