Page MenuHomePhabricator

[RISCV] Add support for using -msave-restore with tailcalls
Needs ReviewPublic

Authored by edward-jones on Nov 18 2020, 8:34 AM.

Details

Summary

This introduces the use of a new compiler runtime library function which behaves the same as riscv_restore_N, however instead of returning to the callee these functions do a tailcall to the function whose pointer is stored in t1. This allows the -msave-restore optimization to be applied even in a tailcall context. The new runtime library functions are called riscv_restore_tailcall_X where X is the number of callee-saved registers which will be restored.

Original patch by Simon Cook.

Diff Detail

Unit TestsFailed

TimeTest
80 mslinux > Clangd Unit Tests._/ClangdTests::FindImplementations.CaptureDefintion
Note: Google Test filter = FindImplementations.CaptureDefintion [==========] Running 1 test from 1 test case. [----------] Global test environment set-up.
80 mslinux > Clangd Unit Tests._/ClangdTests::FindImplementations.Inheritance
Note: Google Test filter = FindImplementations.Inheritance [==========] Running 1 test from 1 test case. [----------] Global test environment set-up.
430 mslinux > HWAddressSanitizer-x86_64.TestCases::sizes.cpp
Script: -- : 'RUN: at line 3'; /mnt/disks/ssd0/agent/llvm-project/build/./bin/clang --driver-mode=g++ -m64 -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld -mcmodel=large -mllvm -hwasan-globals -mllvm -hwasan-use-short-granules -mllvm -hwasan-instrument-landing-pads=0 -mllvm -hwasan-instrument-personality-functions /mnt/disks/ssd0/agent/llvm-project/compiler-rt/test/hwasan/TestCases/sizes.cpp -nostdlib++ -lstdc++ -o /mnt/disks/ssd0/agent/llvm-project/build/projects/compiler-rt/test/hwasan/X86_64/TestCases/Output/sizes.cpp.tmp
160 mswindows > Clangd Unit Tests._/ClangdTests_exe::FindImplementations.CaptureDefintion
Note: Google Test filter = FindImplementations.CaptureDefintion [==========] Running 1 test from 1 test case.
200 mswindows > Clangd Unit Tests._/ClangdTests_exe::FindImplementations.CaptureDefintion
Note: Google Test filter = FindImplementations.CaptureDefintion [==========] Running 1 test from 1 test case.
View Full Test Results (7 Failed)

Event Timeline

edward-jones created this revision.Nov 18 2020, 8:34 AM
edward-jones requested review of this revision.Nov 18 2020, 8:34 AM

Where is this specified? I only see the non-tailcall versions in GCC. I don't think we should merge anything until it's at least a draft specification in an official place.

jrtc27 added inline comments.Nov 18 2020, 8:43 AM
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
850

We should not need to duplicate all this code surely? Certainly these need to honour the code model and not assume medlow.

lenary resigned from this revision.Jan 14 2021, 9:43 AM

I have updated this so that the generation of the address passed to the restore functions is done in a separate method RISCVFrameLowering::buildAddr. This handles both the code models and mirrors RISCVISelLowering::getAddr - it would be nice if these functions could share code, or at least be in a common place.

I've also opened a pull request to document the existing -msave-restore behaviour in riscv-toolchain-conventions, and I have a follow up patch to document the tail call versions of the entry points too.

I've expanded the test to cover the different code models, and pic mode too.

lenary removed a subscriber: lenary.Mon, Apr 19, 11:29 AM