This is an archive of the discontinued LLVM Phabricator instance.

[Sparc] Add tail call support
ClosedPublic

Authored by dcederman on Aug 24 2018, 12:13 AM.

Details

Summary

This patch adds tail call support to the 32-bit Sparc backend.

Two new instructions are defined, TAIL_CALL and TAIL_CALLri. They are encoded the same as CALL and BINDri, but are marked with isReturn so that the epilogue gets emitted. In contrast to CALL, TAIL_CALL is not marked with isCall. This makes it possible to use the leaf function optimization when the only call a function makes is a tail call.

TAIL_CALL modifies the return address in %o7, so for leaf functions the value in %o7 needs to be restored after the call. For normal functions which uses the restore instruction this is not necessary.

Diff Detail

Event Timeline

dcederman created this revision.Aug 24 2018, 12:13 AM
dcederman updated this revision to Diff 180646.Jan 8 2019, 5:39 AM

Do not tail call opt if either the callee or caller returns a struct and the other does not.

jrtc27 added inline comments.Jan 8 2019, 10:17 AM
lib/Target/Sparc/SparcISelLowering.cpp
733

Whilst correct for now given the 64-bit lowering does not support tail calls, this condition only applies to the 32-bit SPARC ABI, as the 64-bit ABI does not have the extra unimp after the delay slot for struct-returning functions. Perhaps worth adding a comment here so this doesn't get forgotten?

dcederman marked an inline comment as done.Jan 9 2019, 4:59 AM
dcederman added inline comments.
lib/Target/Sparc/SparcISelLowering.cpp
733

Ok, I'll add a condition to only disallow this on 32-bit SPARC.

dcederman updated this revision to Diff 180816.Jan 9 2019, 4:59 AM
dcederman edited the summary of this revision. (Show Details)
dcederman added a reviewer: mgrang.

On 64-bit Sparc we can allow tail call optimizations on functions that returns a struct even though the caller does not (and vice versa).

Rebased on master. Changed unsigned into Register in a couple of places and changed "no-frame-pointer-elim" to "frame-pointer" in test.

Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2020, 11:52 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
brad set the repository for this revision to rG LLVM Github Monorepo.Feb 8 2021, 6:21 PM
jrtc27 added inline comments.Feb 8 2021, 6:23 PM
llvm/test/CodeGen/SPARC/tailcall.ll
1 ↗(On Diff #301192)

Perhaps worth using update_llc_test_checks.py, or at least adding some CHECK-NEXTs as the delay slot being filled (rather than something else being silently emitted in between) is pretty important.

dcederman updated this revision to Diff 379376.Oct 13 2021, 7:43 AM

Autogenerated assertions with update_llc_test_checks.py.

dcederman marked an inline comment as done.Oct 13 2021, 7:43 AM
koakuma accepted this revision.Mar 4 2022, 5:25 AM

Looks good to me, also all testcases are passing here:

-- Testing: 93 tests, 48 workers --
PASS: LLVM :: CodeGen/SPARC/2007-05-09-JumpTables.ll (1 of 93)
PASS: LLVM :: CodeGen/SPARC/2012-05-01-LowerArguments.ll (2 of 93)
PASS: LLVM :: CodeGen/SPARC/2008-10-10-InlineAsmMemoryOperand.ll (3 of 93)
PASS: LLVM :: CodeGen/SPARC/2007-07-05-LiveIntervalAssert.ll (4 of 93)
PASS: LLVM :: CodeGen/SPARC/2008-10-10-InlineAsmRegOperand.ll (5 of 93)
PASS: LLVM :: CodeGen/SPARC/2009-08-28-WeakLinkage.ll (6 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-01-22-SRet.ll (7 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-01-21-ByValArgs.ll (8 of 93)
PASS: LLVM :: CodeGen/SPARC/LeonDetectRoundChangePassUT.ll (9 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-12-03-TailDuplication.ll (10 of 93)
PASS: LLVM :: CodeGen/SPARC/2006-01-22-BitConvertLegalize.ll (11 of 93)
PASS: LLVM :: CodeGen/SPARC/cast-sret-func.ll (12 of 93)
PASS: LLVM :: CodeGen/SPARC/DbgValueOtherTargets.test (13 of 93)
PASS: LLVM :: CodeGen/SPARC/64cond.ll (14 of 93)
PASS: LLVM :: CodeGen/SPARC/analyze-branch.ll (15 of 93)
PASS: LLVM :: CodeGen/SPARC/64atomics.ll (16 of 93)
PASS: LLVM :: CodeGen/SPARC/fp128-split.ll (17 of 93)
PASS: LLVM :: CodeGen/SPARC/LeonFixAllFDIVSQRTPassUT.ll (18 of 93)
PASS: LLVM :: CodeGen/SPARC/empty-functions.ll (19 of 93)
PASS: LLVM :: CodeGen/SPARC/64spill.ll (20 of 93)
PASS: LLVM :: CodeGen/SPARC/basictest.ll (21 of 93)
PASS: LLVM :: CodeGen/SPARC/float-constants.ll (22 of 93)
PASS: LLVM :: CodeGen/SPARC/codemodel.ll (23 of 93)
PASS: LLVM :: CodeGen/SPARC/constructor.ll (24 of 93)
PASS: LLVM :: CodeGen/SPARC/inline-asm-i-constraint-i1.ll (25 of 93)
PASS: LLVM :: CodeGen/SPARC/inlineasm-output-template.ll (26 of 93)
PASS: LLVM :: CodeGen/SPARC/imm.ll (27 of 93)
PASS: LLVM :: CodeGen/SPARC/missinglabel.ll (28 of 93)
PASS: LLVM :: CodeGen/SPARC/fshl.ll (29 of 93)
PASS: LLVM :: CodeGen/SPARC/LeonInsertNOPLoadPassUT.ll (30 of 93)
PASS: LLVM :: CodeGen/SPARC/inlineasm-v9.ll (31 of 93)
PASS: LLVM :: CodeGen/SPARC/fail-alloca-align.ll (32 of 93)
PASS: LLVM :: CodeGen/SPARC/leafproc.ll (33 of 93)
PASS: LLVM :: CodeGen/SPARC/pic.ll (34 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-01-11-Call.ll (35 of 93)
PASS: LLVM :: CodeGen/SPARC/parts.ll (36 of 93)
PASS: LLVM :: CodeGen/SPARC/missing-sret.ll (37 of 93)
PASS: LLVM :: CodeGen/SPARC/LeonSMACUMACInstructionUT.ll (38 of 93)
PASS: LLVM :: CodeGen/SPARC/2013-05-17-CallFrame.ll (39 of 93)
PASS: LLVM :: CodeGen/SPARC/inlineasm.ll (40 of 93)
PASS: LLVM :: CodeGen/SPARC/private.ll (41 of 93)
PASS: LLVM :: CodeGen/SPARC/rem.ll (42 of 93)
PASS: LLVM :: CodeGen/SPARC/multiple-div.ll (43 of 93)
PASS: LLVM :: CodeGen/SPARC/readcycle.ll (44 of 93)
PASS: LLVM :: CodeGen/SPARC/register-clobber.ll (45 of 93)
PASS: LLVM :: CodeGen/SPARC/reg64.ll (46 of 93)
PASS: LLVM :: CodeGen/SPARC/inlineasm-bad.ll (47 of 93)
PASS: LLVM :: CodeGen/SPARC/mature-mc-support.ll (48 of 93)
PASS: LLVM :: CodeGen/SPARC/sethiandn.ll (49 of 93)
PASS: LLVM :: CodeGen/SPARC/mult-alt-generic-sparc.ll (50 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-01-19-DelaySlot.ll (51 of 93)
PASS: LLVM :: CodeGen/SPARC/select-mask.ll (52 of 93)
PASS: LLVM :: CodeGen/SPARC/sret-secondary.ll (53 of 93)
PASS: LLVM :: CodeGen/SPARC/spillsize.ll (54 of 93)
PASS: LLVM :: CodeGen/SPARC/obj-relocs.ll (55 of 93)
PASS: LLVM :: CodeGen/SPARC/32abi.ll (56 of 93)
PASS: LLVM :: CodeGen/SPARC/spill.ll (57 of 93)
PASS: LLVM :: CodeGen/SPARC/disable-fsmuld-fmuls.ll (58 of 93)
PASS: LLVM :: CodeGen/SPARC/2009-08-28-PIC.ll (59 of 93)
PASS: LLVM :: CodeGen/SPARC/64bit.ll (60 of 93)
PASS: LLVM :: CodeGen/SPARC/soft-mul-div.ll (61 of 93)
PASS: LLVM :: CodeGen/SPARC/trap.ll (62 of 93)
PASS: LLVM :: CodeGen/SPARC/reserved-regs.ll (63 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-01-11-CC.ll (64 of 93)
PASS: LLVM :: CodeGen/SPARC/varargs-v8.ll (65 of 93)
PASS: LLVM :: CodeGen/SPARC/LeonItinerariesUT.ll (66 of 93)
PASS: LLVM :: CodeGen/SPARC/zerostructcall.ll (67 of 93)
PASS: LLVM :: CodeGen/SPARC/vector-extract-elt.ll (68 of 93)
PASS: LLVM :: CodeGen/SPARC/vector-call.ll (69 of 93)
PASS: LLVM :: CodeGen/SPARC/stack-align.ll (70 of 93)
PASS: LLVM :: CodeGen/SPARC/tailcall.ll (71 of 93)
PASS: LLVM :: CodeGen/SPARC/soft-float.ll (72 of 93)
PASS: LLVM :: CodeGen/SPARC/setjmp.ll (73 of 93)
PASS: LLVM :: CodeGen/SPARC/thread-pointer.ll (74 of 93)
PASS: LLVM :: CodeGen/SPARC/overflow-intrinsic-optimizations.ll (75 of 93)
PASS: LLVM :: CodeGen/SPARC/2011-01-11-FrameAddr.ll (76 of 93)
PASS: LLVM :: CodeGen/SPARC/64abi.ll (77 of 93)
PASS: LLVM :: CodeGen/SPARC/exception.ll (78 of 93)
PASS: LLVM :: CodeGen/SPARC/smulo-128-legalisation-lowering.ll (79 of 93)
PASS: LLVM :: CodeGen/SPARC/varargs.ll (80 of 93)
PASS: LLVM :: CodeGen/SPARC/umulo-128-legalisation-lowering.ll (81 of 93)
PASS: LLVM :: CodeGen/SPARC/blockaddr.ll (82 of 93)
PASS: LLVM :: CodeGen/SPARC/atomics.ll (83 of 93)
PASS: LLVM :: CodeGen/SPARC/constpool.ll (84 of 93)
PASS: LLVM :: CodeGen/SPARC/stack-protector.ll (85 of 93)
PASS: LLVM :: CodeGen/SPARC/globals.ll (86 of 93)
PASS: LLVM :: CodeGen/SPARC/func-addr.ll (87 of 93)
PASS: LLVM :: CodeGen/SPARC/float.ll (88 of 93)
PASS: LLVM :: CodeGen/SPARC/fp16-promote.ll (89 of 93)
PASS: LLVM :: CodeGen/SPARC/ctpop.ll (90 of 93)
PASS: LLVM :: CodeGen/SPARC/tls.ll (91 of 93)
PASS: LLVM :: CodeGen/SPARC/LeonCASAInstructionUT.ll (92 of 93)
PASS: LLVM :: CodeGen/SPARC/fp128.ll (93 of 93)

Testing Time: 52.30s
  Passed: 93
This revision is now accepted and ready to land.Mar 4 2022, 5:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 5:25 AM
This revision was landed with ongoing or failed builds.Mar 8 2022, 4:52 AM
This revision was automatically updated to reflect the committed changes.