This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][GlobalISel] Add lowerFormalArguments for calling convention
ClosedPublic

Authored by nitinjohnraj on Feb 21 2020, 11:34 AM.

Details

Summary

This patch adds an IncomingValueHandler and IncomingValueAssigner, and implements minimal support for lowering formal arguments according to the RISC-V calling convention. Simple non-aggregate integer and pointer types are supported.

In the future, we must correctly handle byval and sret pointer arguments, and instances where the number of arguments exceeds the number of registers.

Diff Detail

Event Timeline

lewis-revill created this revision.Feb 21 2020, 11:34 AM

Rebase, update test structure.

Joe added inline comments.Mar 20 2020, 7:52 AM
llvm/lib/Target/RISCV/RISCVCallLowering.cpp
171

Perhaps add a test for this?

173

Floats don't work here. HandleAssignments tries to truncate it. Best to leave it unsupported for now.

lewis-revill edited the summary of this revision. (Show Details)

Address comments relating to supported types.

lenary resigned from this revision.Jan 14 2021, 10:10 AM
rkruppe removed a subscriber: rkruppe.Jan 14 2021, 10:20 AM
lewis-revill edited the summary of this revision. (Show Details)

Rebased, and updated where appropriate to continue to build correctly.

arsenm added inline comments.Jan 17 2022, 4:42 PM
llvm/lib/Target/RISCV/RISCVCallLowering.cpp
201

Same as other patches, don't copy your own splitToValueTypes

lewis-revill edited the summary of this revision. (Show Details)

Introduce an IncomingValueAssigner to allow us to call determineAndHandleAssignments.

lewis-revill marked 3 inline comments as done.Jan 26 2022, 4:02 AM
lewis-revill retitled this revision from [WIP][RISCV][GlobalISel] Add lowerFormalArguments for calling convention to [RISCV][GlobalISel] Add lowerFormalArguments for calling convention.Feb 9 2022, 3:12 AM
arsenm added inline comments.Feb 9 2022, 8:46 AM
llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/args.ll
257 ↗(On Diff #403204)

Probably should have some byval, sret, and cases where the argument list runs out of registers. Same for return values / hidden sret

nitinjohnraj commandeered this revision.Apr 5 2023, 1:06 PM
nitinjohnraj added a reviewer: lewis-revill.
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 1:06 PM

Updated parent revision

llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/args.ll
257 ↗(On Diff #403204)

Probably should have some byval, sret,

Correct me if I'm wrong, but byval and sret both require support for aggregate types, which this patch doesn't support.

sret, and cases where the argument list runs out of registers.

Do you have an example of a similar test? I wasn't aware that we could run out of registers at this phase, I thought that we could have an unlimited number of virtual registers.

arsenm added inline comments.May 22 2023, 9:44 AM
llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/args.ll
257 ↗(On Diff #403204)

This is wrong. sret and byval do not really have anything to do with aggregate types, and apply to pointers. You see them on a pointer argument, not aggregate. They would typically be used with an aggregate in memory type, but the in-memory type can be anything

You're mapping to an ABI constraint. If you had 4 32-bit registers for argument passing, you would run out of argument passing registers and have one stack passed argument for (i32, i32, i32, i32, i32).

I am blind. Was there an opaque pointer test?

arsenm added inline comments.May 22 2023, 9:48 AM
llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/args.ll
233 ↗(On Diff #524360)

Should only have opaque pointers

Could you also add a test with^TM too many arguments.

Could you also add a test with^TM too many arguments.

A variety of types in the excess region would also be good. There can be bugs in the memory vs register type

craig.topper added inline comments.May 22 2023, 4:27 PM
llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
217 ↗(On Diff #524360)

Use single space after //

evandro removed a subscriber: evandro.May 22 2023, 5:24 PM
nitinjohnraj marked 3 inline comments as done.

Used opaque pointers, added tests for byval and sret

nitinjohnraj added inline comments.May 30 2023, 8:51 AM
llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/args.ll
257 ↗(On Diff #403204)

Thanks for the detailed feedback! I have added tests for sret and byval; however, this patch doesn't currently handle them correctly, I suspect. I'm referring to SelectionDAG for RISCV to figure out how to support them, but I plan to add them in an upcoming patch.

I have not added a test for when we run out of argument passing registers, as it requires the implementation of getStackAddress. That'll be added in an upcoming patch as well.

arsenm accepted this revision.May 30 2023, 10:37 AM
This revision is now accepted and ready to land.May 30 2023, 10:37 AM
nitinjohnraj edited the summary of this revision. (Show Details)May 30 2023, 11:20 AM