This is an archive of the discontinued LLVM Phabricator instance.

[builtins][ARM] Replace call_apsr.S with inline asm
ClosedPublic

Authored by rprichard on Jun 18 2020, 11:43 PM.

Details

Summary

The %arm_call_apsr expansion doesn't work when config.clang is a clang
driver defaulting to a non-ARM arch. Rather than fix it, replace
call_apsr.S with inline asm in call_apsr.h, which also resolves the
FIXME added in D31259.

Maybe the __attribute__((noinline,pcs("aapcs"))) attributes are
unnecessary on the static functions, but I was unsure what liberty the
compiler had to insert instructions that modified the condition codes,
so it seemed helpful.

Diff Detail

Event Timeline

rprichard created this revision.Jun 18 2020, 11:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2020, 11:43 PM
Herald added subscribers: Restricted Project, danielkiss, kristof.beyls. · View Herald Transcript

I needed this change to run the builtins' unit tests in an arm32 NDK configuration, but I'm not very confident in it. Without the change, the tests failed because the arm -march flag didn't work with clang's default host architecture (e.g. x86_64).

I dont think that there is a guarantee that target_cflags will include -target armv7-unknown-linux-androideabi. Can we explicitly set the target triple instead?

@jmgao added the call_apsr functions in D12089. At that point, I think the builtins only had a test bash script for testing. D30802 and D31259 added lit support, and the second one added the lit.cfg file setting %arm_call_apsr.

It seems that lit.cfg would have only worked if config.clang's default arch was ARM.

AFAICT, target_arch is a string like "i686", "x86_64", "arm", or "aarch64", so it doesn't generally make sense to add that to -march. call_aprs.S is ARM code, so we correct target_arch from "arm" to "armv7" above.

D31259 also added this line:

# FIXME: move the call_apsr.s into call_apsr.h as inline-asm.

If we still want to do that, that ought to be easy.

I dont think that there is a guarantee that target_cflags will include -target armv7-unknown-linux-androideabi. Can we explicitly set the target triple instead?

I think that's right, but we're using target_cflags to compile all the unit test C files (via %clang_builtins), so it ought to do the right thing for the asm file too? It won't matter if I remove this code, though.

rprichard updated this revision to Diff 276976.Jul 10 2020, 3:44 AM

Replace call_apsr.S with inline asm in call_apsr.h.

rprichard retitled this revision from [builtins] Use target_cflags for %arm_call_apsr to [builtins][ARM] Replace call_apsr.S with inline asm.Jul 10 2020, 3:48 AM
rprichard edited the summary of this revision. (Show Details)
rprichard edited the summary of this revision. (Show Details)
compnerd accepted this revision.Jul 10 2020, 9:41 AM

I really like this approach way better. Thank you!

This revision is now accepted and ready to land.Jul 10 2020, 9:41 AM
This revision was automatically updated to reflect the committed changes.
compiler-rt/test/builtins/Unit/arm/call_apsr.h