[RISCV] Support fixed-length vectors in the calling convention
authorFraser Cormack <fraser@codeplay.com>
Tue, 2 Mar 2021 11:11:18 +0000 (11:11 +0000)
committerFraser Cormack <fraser@codeplay.com>
Mon, 15 Mar 2021 10:43:51 +0000 (10:43 +0000)
commit0c5b789c7342ee8384507c3242fc256e23248c4d
treee9ae014af4fe9ff548fe7aea11e55214eba9742b
parent5d48b45ce3bf45f8b8e1195fd74287ba90d70e89
[RISCV] Support fixed-length vectors in the calling convention

This patch adds fixed-length vector support to the calling convention
when RVV is used to lower fixed-length vectors. The scheme follows the
regular vector calling convention for the argument/return registers, but
uses scalable vector container types as the LocVTs, and converts to/from
the fixed-length vector value types as required.

Fixed-length vector types may be split when the combination of minimum
VLEN and the maximum allowable LMUL is not large enough to fully contain
the vector. In this case the behaviour differs between fixed-length
vectors passed as parameters and as return values:
1. For return values, vectors must be passed entirely via registers or
via the stack.
2. For parameters, unlike scalar values, split vectors continue to be
passed by value, and are split across multiple registers until there are
no remaining registers. Thus vector parameters may be found partly in
registers and partly on the stack.

As with scalable vectors, the first fixed-length mask vector is passed
via v0. Split mask fixed-length vectors are passed first via v0 and then
via the next available vector register: v8,v9,etc.

The handling of vector return values uses all available argument
registers v8-v23 which does not adhere to the calling convention we're
supposedly implementing, but since this issue affects both fixed-length
and scalable-vector values, it was left as-is.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D97954
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-calling-conv.ll [new file with mode: 0644]