[PATCH] D84636: [RFC] Make the default LibCall implementations from compiler-rt builtins library more customizable

Anatoly Trosinenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 27 04:58:52 PDT 2020


atrosinenko created this revision.
atrosinenko added reviewers: asl, howard.hinnant, samsonov, t.p.northover.
Herald added subscribers: Sanitizers, kristof.beyls, krytarowski.
Herald added a project: Sanitizers.
atrosinenko edited the summary of this revision.
atrosinenko retitled this revision from "[WIP] Create infrastructure for customizing the default LibCall implementations" to "[RFC] Make the default LibCall implementations from compiler-rt builtins library more customizable".
Herald added a subscriber: dberris.
atrosinenko added reviewers: compnerd, phosek.
atrosinenko requested review of this revision.

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 <https://www.ti.com/lit/an/slaa534a/slaa534a.pdf>). //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.

- **-** 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)
- **+** 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
- **+** 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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84636

Files:
  compiler-rt/lib/builtins/absvdi2.c
  compiler-rt/lib/builtins/absvsi2.c
  compiler-rt/lib/builtins/absvti2.c
  compiler-rt/lib/builtins/adddf3.c
  compiler-rt/lib/builtins/addsf3.c
  compiler-rt/lib/builtins/addtf3.c
  compiler-rt/lib/builtins/addvdi3.c
  compiler-rt/lib/builtins/addvsi3.c
  compiler-rt/lib/builtins/addvti3.c
  compiler-rt/lib/builtins/arm-libcall-overrides.h
  compiler-rt/lib/builtins/ashldi3.c
  compiler-rt/lib/builtins/ashlti3.c
  compiler-rt/lib/builtins/ashrdi3.c
  compiler-rt/lib/builtins/ashrti3.c
  compiler-rt/lib/builtins/bswapdi2.c
  compiler-rt/lib/builtins/bswapsi2.c
  compiler-rt/lib/builtins/clzdi2.c
  compiler-rt/lib/builtins/clzsi2.c
  compiler-rt/lib/builtins/clzti2.c
  compiler-rt/lib/builtins/cmpdi2.c
  compiler-rt/lib/builtins/cmpti2.c
  compiler-rt/lib/builtins/comparedf2.c
  compiler-rt/lib/builtins/comparesf2.c
  compiler-rt/lib/builtins/comparetf2.c
  compiler-rt/lib/builtins/ctzdi2.c
  compiler-rt/lib/builtins/ctzsi2.c
  compiler-rt/lib/builtins/ctzti2.c
  compiler-rt/lib/builtins/divdc3.c
  compiler-rt/lib/builtins/divdf3.c
  compiler-rt/lib/builtins/divdi3.c
  compiler-rt/lib/builtins/divmoddi4.c
  compiler-rt/lib/builtins/divmodsi4.c
  compiler-rt/lib/builtins/divsc3.c
  compiler-rt/lib/builtins/divsf3.c
  compiler-rt/lib/builtins/divsi3.c
  compiler-rt/lib/builtins/divtc3.c
  compiler-rt/lib/builtins/divtf3.c
  compiler-rt/lib/builtins/divti3.c
  compiler-rt/lib/builtins/divxc3.c
  compiler-rt/lib/builtins/enable_execute_stack.c
  compiler-rt/lib/builtins/eprintf.c
  compiler-rt/lib/builtins/extenddftf2.c
  compiler-rt/lib/builtins/extendhfsf2.c
  compiler-rt/lib/builtins/extendsfdf2.c
  compiler-rt/lib/builtins/extendsftf2.c
  compiler-rt/lib/builtins/ffsdi2.c
  compiler-rt/lib/builtins/ffssi2.c
  compiler-rt/lib/builtins/ffsti2.c
  compiler-rt/lib/builtins/fixdfdi.c
  compiler-rt/lib/builtins/fixdfsi.c
  compiler-rt/lib/builtins/fixdfti.c
  compiler-rt/lib/builtins/fixsfdi.c
  compiler-rt/lib/builtins/fixsfsi.c
  compiler-rt/lib/builtins/fixsfti.c
  compiler-rt/lib/builtins/fixtfdi.c
  compiler-rt/lib/builtins/fixtfsi.c
  compiler-rt/lib/builtins/fixtfti.c
  compiler-rt/lib/builtins/fixunsdfdi.c
  compiler-rt/lib/builtins/fixunsdfsi.c
  compiler-rt/lib/builtins/fixunsdfti.c
  compiler-rt/lib/builtins/fixunssfdi.c
  compiler-rt/lib/builtins/fixunssfsi.c
  compiler-rt/lib/builtins/fixunssfti.c
  compiler-rt/lib/builtins/fixunstfdi.c
  compiler-rt/lib/builtins/fixunstfsi.c
  compiler-rt/lib/builtins/fixunstfti.c
  compiler-rt/lib/builtins/fixunsxfdi.c
  compiler-rt/lib/builtins/fixunsxfsi.c
  compiler-rt/lib/builtins/fixunsxfti.c
  compiler-rt/lib/builtins/fixxfdi.c
  compiler-rt/lib/builtins/fixxfti.c
  compiler-rt/lib/builtins/floatdidf.c
  compiler-rt/lib/builtins/floatdisf.c
  compiler-rt/lib/builtins/floatditf.c
  compiler-rt/lib/builtins/floatdixf.c
  compiler-rt/lib/builtins/floatsidf.c
  compiler-rt/lib/builtins/floatsisf.c
  compiler-rt/lib/builtins/floatsitf.c
  compiler-rt/lib/builtins/floattidf.c
  compiler-rt/lib/builtins/floattisf.c
  compiler-rt/lib/builtins/floattitf.c
  compiler-rt/lib/builtins/floattixf.c
  compiler-rt/lib/builtins/floatundidf.c
  compiler-rt/lib/builtins/floatundisf.c
  compiler-rt/lib/builtins/floatunditf.c
  compiler-rt/lib/builtins/floatundixf.c
  compiler-rt/lib/builtins/floatunsidf.c
  compiler-rt/lib/builtins/floatunsisf.c
  compiler-rt/lib/builtins/floatunsitf.c
  compiler-rt/lib/builtins/floatuntidf.c
  compiler-rt/lib/builtins/floatuntisf.c
  compiler-rt/lib/builtins/floatuntitf.c
  compiler-rt/lib/builtins/floatuntixf.c
  compiler-rt/lib/builtins/fp_lib.h
  compiler-rt/lib/builtins/gcc_personality_v0.c
  compiler-rt/lib/builtins/int_lib.h
  compiler-rt/lib/builtins/libcall-set-defaults.inc
  compiler-rt/lib/builtins/lshrdi3.c
  compiler-rt/lib/builtins/lshrti3.c
  compiler-rt/lib/builtins/mingw_fixfloat.c
  compiler-rt/lib/builtins/moddi3.c
  compiler-rt/lib/builtins/modsi3.c
  compiler-rt/lib/builtins/modti3.c
  compiler-rt/lib/builtins/muldc3.c
  compiler-rt/lib/builtins/muldf3.c
  compiler-rt/lib/builtins/muldi3.c
  compiler-rt/lib/builtins/mulodi4.c
  compiler-rt/lib/builtins/mulosi4.c
  compiler-rt/lib/builtins/muloti4.c
  compiler-rt/lib/builtins/mulsc3.c
  compiler-rt/lib/builtins/mulsf3.c
  compiler-rt/lib/builtins/multc3.c
  compiler-rt/lib/builtins/multf3.c
  compiler-rt/lib/builtins/multi3.c
  compiler-rt/lib/builtins/mulvdi3.c
  compiler-rt/lib/builtins/mulvsi3.c
  compiler-rt/lib/builtins/mulvti3.c
  compiler-rt/lib/builtins/mulxc3.c
  compiler-rt/lib/builtins/negdf2.c
  compiler-rt/lib/builtins/negdi2.c
  compiler-rt/lib/builtins/negsf2.c
  compiler-rt/lib/builtins/negti2.c
  compiler-rt/lib/builtins/negvdi2.c
  compiler-rt/lib/builtins/negvsi2.c
  compiler-rt/lib/builtins/negvti2.c
  compiler-rt/lib/builtins/paritydi2.c
  compiler-rt/lib/builtins/paritysi2.c
  compiler-rt/lib/builtins/parityti2.c
  compiler-rt/lib/builtins/popcountdi2.c
  compiler-rt/lib/builtins/popcountsi2.c
  compiler-rt/lib/builtins/popcountti2.c
  compiler-rt/lib/builtins/powidf2.c
  compiler-rt/lib/builtins/powisf2.c
  compiler-rt/lib/builtins/powitf2.c
  compiler-rt/lib/builtins/powixf2.c
  compiler-rt/lib/builtins/subdf3.c
  compiler-rt/lib/builtins/subsf3.c
  compiler-rt/lib/builtins/subtf3.c
  compiler-rt/lib/builtins/subvdi3.c
  compiler-rt/lib/builtins/subvsi3.c
  compiler-rt/lib/builtins/subvti3.c
  compiler-rt/lib/builtins/trampoline_setup.c
  compiler-rt/lib/builtins/truncdfhf2.c
  compiler-rt/lib/builtins/truncdfsf2.c
  compiler-rt/lib/builtins/truncsfhf2.c
  compiler-rt/lib/builtins/trunctfdf2.c
  compiler-rt/lib/builtins/trunctfsf2.c
  compiler-rt/lib/builtins/ucmpdi2.c
  compiler-rt/lib/builtins/ucmpti2.c
  compiler-rt/lib/builtins/udivdi3.c
  compiler-rt/lib/builtins/udivmoddi4.c
  compiler-rt/lib/builtins/udivmodsi4.c
  compiler-rt/lib/builtins/udivmodti4.c
  compiler-rt/lib/builtins/udivsi3.c
  compiler-rt/lib/builtins/udivti3.c
  compiler-rt/lib/builtins/umoddi3.c
  compiler-rt/lib/builtins/umodsi3.c
  compiler-rt/lib/builtins/umodti3.c
  compiler-rt/test/builtins/Unit/absvdi2_test.c
  compiler-rt/test/builtins/Unit/absvsi2_test.c
  compiler-rt/test/builtins/Unit/absvti2_test.c
  compiler-rt/test/builtins/Unit/adddf3vfp_test.c
  compiler-rt/test/builtins/Unit/addsf3vfp_test.c
  compiler-rt/test/builtins/Unit/addtf3_test.c
  compiler-rt/test/builtins/Unit/addvdi3_test.c
  compiler-rt/test/builtins/Unit/addvsi3_test.c
  compiler-rt/test/builtins/Unit/addvti3_test.c
  compiler-rt/test/builtins/Unit/ashldi3_test.c
  compiler-rt/test/builtins/Unit/ashlti3_test.c
  compiler-rt/test/builtins/Unit/ashrdi3_test.c
  compiler-rt/test/builtins/Unit/ashrti3_test.c
  compiler-rt/test/builtins/Unit/clzdi2_test.c
  compiler-rt/test/builtins/Unit/clzsi2_test.c
  compiler-rt/test/builtins/Unit/clzti2_test.c
  compiler-rt/test/builtins/Unit/cmpdi2_test.c
  compiler-rt/test/builtins/Unit/cmpti2_test.c
  compiler-rt/test/builtins/Unit/ctzdi2_test.c
  compiler-rt/test/builtins/Unit/ctzsi2_test.c
  compiler-rt/test/builtins/Unit/ctzti2_test.c
  compiler-rt/test/builtins/Unit/divdc3_test.c
  compiler-rt/test/builtins/Unit/divdf3_test.c
  compiler-rt/test/builtins/Unit/divdf3vfp_test.c
  compiler-rt/test/builtins/Unit/divdi3_test.c
  compiler-rt/test/builtins/Unit/divmodsi4_test.c
  compiler-rt/test/builtins/Unit/divsc3_test.c
  compiler-rt/test/builtins/Unit/divsf3_test.c
  compiler-rt/test/builtins/Unit/divsf3vfp_test.c
  compiler-rt/test/builtins/Unit/divsi3_test.c
  compiler-rt/test/builtins/Unit/divtc3_test.c
  compiler-rt/test/builtins/Unit/divtf3_test.c
  compiler-rt/test/builtins/Unit/divti3_test.c
  compiler-rt/test/builtins/Unit/divxc3_test.c
  compiler-rt/test/builtins/Unit/extenddftf2_test.c
  compiler-rt/test/builtins/Unit/extendsfdf2vfp_test.c
  compiler-rt/test/builtins/Unit/extendsftf2_test.c
  compiler-rt/test/builtins/Unit/ffsdi2_test.c
  compiler-rt/test/builtins/Unit/ffssi2_test.c
  compiler-rt/test/builtins/Unit/ffsti2_test.c
  compiler-rt/test/builtins/Unit/fixdfdi_test.c
  compiler-rt/test/builtins/Unit/fixdfti_test.c
  compiler-rt/test/builtins/Unit/fixsfdi_test.c
  compiler-rt/test/builtins/Unit/fixsfti_test.c
  compiler-rt/test/builtins/Unit/fixunsdfdi_test.c
  compiler-rt/test/builtins/Unit/fixunsdfsi_test.c
  compiler-rt/test/builtins/Unit/fixunsdfsivfp_test.c
  compiler-rt/test/builtins/Unit/fixunsdfti_test.c
  compiler-rt/test/builtins/Unit/fixunssfdi_test.c
  compiler-rt/test/builtins/Unit/fixunssfsi_test.c
  compiler-rt/test/builtins/Unit/fixunssfti_test.c
  compiler-rt/test/builtins/Unit/fixunstfdi_test.c
  compiler-rt/test/builtins/Unit/fixunstfti_test.c
  compiler-rt/test/builtins/Unit/fixunsxfdi_test.c
  compiler-rt/test/builtins/Unit/fixunsxfsi_test.c
  compiler-rt/test/builtins/Unit/fixunsxfti_test.c
  compiler-rt/test/builtins/Unit/fixxfdi_test.c
  compiler-rt/test/builtins/Unit/fixxfti_test.c
  compiler-rt/test/builtins/Unit/floatdidf_test.c
  compiler-rt/test/builtins/Unit/floatdisf_test.c
  compiler-rt/test/builtins/Unit/floatditf_test.c
  compiler-rt/test/builtins/Unit/floatdixf_test.c
  compiler-rt/test/builtins/Unit/floatsidfvfp_test.c
  compiler-rt/test/builtins/Unit/floatsisfvfp_test.c
  compiler-rt/test/builtins/Unit/floatsitf_test.c
  compiler-rt/test/builtins/Unit/floattidf_test.c
  compiler-rt/test/builtins/Unit/floattisf_test.c
  compiler-rt/test/builtins/Unit/floattitf_test.c
  compiler-rt/test/builtins/Unit/floattixf_test.c
  compiler-rt/test/builtins/Unit/floatundidf_test.c
  compiler-rt/test/builtins/Unit/floatundisf_test.c
  compiler-rt/test/builtins/Unit/floatunditf_test.c
  compiler-rt/test/builtins/Unit/floatundixf_test.c
  compiler-rt/test/builtins/Unit/floatunsitf_test.c
  compiler-rt/test/builtins/Unit/floatunssidfvfp_test.c
  compiler-rt/test/builtins/Unit/floatunssisfvfp_test.c
  compiler-rt/test/builtins/Unit/floatuntidf_test.c
  compiler-rt/test/builtins/Unit/floatuntisf_test.c
  compiler-rt/test/builtins/Unit/floatuntitf_test.c
  compiler-rt/test/builtins/Unit/floatuntixf_test.c
  compiler-rt/test/builtins/Unit/lshrdi3_test.c
  compiler-rt/test/builtins/Unit/lshrti3_test.c
  compiler-rt/test/builtins/Unit/moddi3_test.c
  compiler-rt/test/builtins/Unit/modsi3_test.c
  compiler-rt/test/builtins/Unit/modti3_test.c
  compiler-rt/test/builtins/Unit/muldc3_test.c
  compiler-rt/test/builtins/Unit/muldf3vfp_test.c
  compiler-rt/test/builtins/Unit/muldi3_test.c
  compiler-rt/test/builtins/Unit/mulodi4_test.c
  compiler-rt/test/builtins/Unit/mulosi4_test.c
  compiler-rt/test/builtins/Unit/muloti4_test.c
  compiler-rt/test/builtins/Unit/mulsc3_test.c
  (45 more files...)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84636.280855.patch
Type: text/x-patch
Size: 190135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200727/dc218286/attachment-0001.bin>


More information about the cfe-commits mailing list