31 Commits

Author SHA1 Message Date
David Green
ac321cbb03
[AArch64][GlobalISel] Legalize Insert vector element (#81453)
This attempts to standardize and extend some of the insert vector
element lowering. Most notably:
- More types are handled by splitting illegal vectors.
- The index type for G_INSERT_VECTOR_ELT is canonicalized to
  TLI.getVectorIdxTy(), similar to extact_vector_element.
- Some of the existing patterns now have the index type specified to
  make sure they can apply to GISel too.
- The C++ selection code has been removed, relying on tablegen patterns.
- G_INSERT_VECTOR_ELT with small GPR input elements are pre-selected to
  use a i32 type, allowing the existing patterns to apply.
- Variable index inserts are lowered in post-legalizer lowering,
  expanding into a stack store and reload.
2024-04-08 08:44:13 +01:00
Jiahan Xie
4bf06bebb9
[GISEL][RISCV] IRTranslator for scalable vector load (#80006)
Add IRTranslator for scalable vector load instruction and include
corresponding tests with alignment argument included, which can be
smaller/equal/larger than element size or smaller/equal/larger than the
minimum total vector size.
2024-03-19 20:12:26 -04:00
Michael Maitland
96049fcf4e [GISEL] Add IRTranslation for shufflevector on scalable vector types (#80378)
Recommits llvm/llvm-project#80378 which was reverted in
llvm/llvm-project#84330. The problem was that the change in
llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir used
217 as an opcode instead of a regex.
2024-03-07 09:10:03 -08:00
Michael Maitland
552da24843
Revert "[GISEL] Add IRTranslation for shufflevector on scalable vector types" (#84330)
Reverts llvm/llvm-project#80378

causing Buildbot failures that did not show up with check-llvm or CI.
2024-03-07 10:16:31 -05:00
Michael Maitland
2b8aaef09e
[GISEL] Add IRTranslation for shufflevector on scalable vector types (#80378)
This patch is stacked on
https://github.com/llvm/llvm-project/pull/80372,
https://github.com/llvm/llvm-project/pull/80307, and
https://github.com/llvm/llvm-project/pull/80306.

ShuffleVector on scalable vector types gets IRTranslate'd to
G_SPLAT_VECTOR since a ShuffleVector that has operates on scalable
vectors is a splat vector where the value of the splat vector is the 0th
element of the first operand, because the index mask operand is the
zeroinitializer (undef and poison are treated as zeroinitializer here).
This is analogous to what happens in SelectionDAG for ShuffleVector.

`buildSplatVector` is renamed to`buildBuildVectorSplatVector`. I did not
make this a separate patch because it would cause problems to revert
that change without reverting this change too.
2024-03-07 09:50:29 -05:00
Michael Maitland
44a46a0b68
[RISCV][GISEL] Add IRTranslation for insertelement with scalable vector type (#80377)
This patch is stacked on #80372, #80307, and #80306.
2024-02-19 15:30:48 -05:00
Michael Maitland
3967510032
[RISCV][GISel] First mask argument placed in v0 according to RISCV Ve… (#79343)
…ctor CC.
2024-01-24 16:03:38 -05:00
Craig Topper
b788692fa5 [RISCV][NFC] Remove unused CHECK prefixes to fix buildbots. NFC 2024-01-09 23:37:18 -08:00
jiahanxie353
e42a70afab [RISCV][GISel] IRTranslate and Legalize some instructions with scalable vector type
* Add IRTranslate tests for ADD, SUB, AND, OR, and XOR with scalable
  vector types to show that they work as expected.
* Legalize G_ADD, G_SUB, G_AND, G_OR, and G_XOR of scalable vector
  type for the RISC-V vector extension.
2024-01-09 21:51:30 -07:00
Fangrui Song
360996ac5a
[RISCV] Merge machine operand flag MO_PLT into MO_CALL (#77253)
Since #72467, `@plt` in assembly output "call foo@plt" is omitted. We
can trivially merge MO_PLT and MO_CALL without any functional change to
assembly/relocatable file output.

Earlier architectures use different call relocation types whether a PLT
is potentially needed: R_386_PLT32/R_386_PC32, R_68K_PLT32/R_68K_PC32,
R_SPARC_WDISP30/R_SPARC_WPLT320. However, as the PLT property is
per-symbol instead of per-call-site and linkers can optimize out a PLT,
the distinction has been confusing.

Arm made good names R_ARM_CALL/R_AARCH64_CALL. Let's use MO_CALL instead
of MO_PLT.

As follow-ups, we can merge fixup_riscv_call/fixup_riscv_call_plt and
VK_RISCV_CALL/VK_RISCV_CALL_PLT.
2024-01-07 12:43:39 -08:00
Michael Maitland
3a38baa0e7
[GISEL][RISCV] Legalize llvm.vacopy intrinsic (#73066)
In the future, we can consider adding a G_VACOPY opcode instead of going
through the GIntrinsic for all targets. We do the approach in this patch
because that is what other targets do today.
2023-12-08 13:45:32 -05:00
Craig Topper
3c5b42acd3
[RISCV] Allocate the varargs GPR save area as a single object. (#74354)
Previously we allocated one object for each GPR. We also allocated the
same offset twice, once to save for VASTART and then again for the first
register in the save loop.

This patch uses a single object for all the registers and shares this
with VASTART. This is more consistent with other targets like AArch64
and ARM.

I've removed the setValue(nullptr) from the memory operand now. Having a
single object makes me a lot more comfortable about alias analysis being
able to see what is going on. This led to the scheduling changes in
push-pop-popret.ll and vararg.ll.
2023-12-05 10:30:01 -08:00
Michael Maitland
12326f5ff0
[RISCV][GISEL] lowerFormalArguments for variadic arguments (#73064)
This is based of the varargs coe in RISCVTargetLowering::LowerFormalArguments.
2023-11-30 12:15:35 -05:00
Michael Maitland
dbb9043dea
[RISCV][GISEL] legalize, regbankselect, and instruction-select for G_… (#73061)
…[UN]MERGE_VALUES

When MERGE or UNMERGE s64 on a subtarget that is non-64bit, it must have
the D extension and use FPR in order to be legal.

All other instances of MERGE and UNMERGE that can be made legal should
be narrowed, widend, or replaced by the combiner.
2023-11-30 11:53:25 -05:00
Craig Topper
9e86919626
[RISCV][GISel] Fix 2 indirect call bugs. (#73170)
We can't set MO_PLT on an indirect call.
We need to constrain the register class for the operand to the call
instruction.
2023-11-27 12:59:01 -08:00
Fangrui Song
103811a27a
[RISCV,GISel] Unconditionally use MO_PLT for calls (#72355)
All known linkers handle R_RISCV_CALL and R_RISCV_CALL_PLT in the same
way (GNU ld since
https://sourceware.org/pipermail/binutils/2020-August/112750.html).

MO_CALL is for R_RISCV_CALL, a deprecated relocation type. We don't
migrate away from MO_CALL yet.
For GISel we don't have the output difference concern and should weigh
more on simplicity.
2023-11-15 15:18:47 -08:00
Michael Maitland
725e599637
[RISCV][GISEL] Add support for scalable vector types in lowerReturnVal (#71587)
Scalable vector types from LLVM IR are lowered into physical vector
registers in MIR based on calling convention for return instructions.
2023-11-15 17:30:53 -05:00
Michael Maitland
a4f77f1ca3
[RISCV][GISEL] Use MO_PLT when Callee is a Global or Symbol (#71982)
SelectionDAG does the same thing in 74c83649547c2
2023-11-14 18:55:39 -05:00
Michael Maitland
a7bbcc4690
[RISCV][GISEL] Add support for lowerFormalArguments that contain scalable vector types (#70882)
Scalable vector types from LLVM IR can be lowered to scalable vector
types in MIR according to the RISCVAssignFn.
2023-11-14 13:15:41 -05:00
Michael Maitland
ac4ff6168a
[CodeGen][MachineVerifier] Use TypeSize instead of unsigned for getRe… (#70881)
…gSizeInBits

This patch changes getRegSizeInBits to return a TypeSize instead of an
unsigned in the case that a virtual register has a scalable LLT. In the
case that register is physical, a Fixed TypeSize is returned.

The MachineVerifier pass is updated to allow copies between fixed and
scalable operands as long as the Src size will fit into the Dest size.

This is a precommit which will be stacked on by a change to GISel to
generate COPYs with a scalable destination but a fixed size source.

This patch is stacked on https://github.com/llvm/llvm-project/pull/70893
for the ability to use scalable vector types in MIR tests.
2023-11-07 14:38:46 -05:00
Craig Topper
9f6010d09e [RISCV][GISel] Emit ADJCALLSTACKDOWN/UP instructions in RISCVCallLowering::lowerCall.
This is needed to mark the stack usage for the call.

With this change, I'm now able to succesfully execute spec2006int
compiled with -O0. There are still many fallbacks that need to be
addressed.
2023-11-05 18:26:45 -08:00
Craig Topper
f4bc18916a [RISCV][GISel] Pass the IsFixed flag into CC_RISCV for outgoing arguments.
This is needed to make FP values be pased in a GPR as required by
the variadic function ABI.
2023-11-05 13:06:23 -08:00
Craig Topper
5d2f9aee66 [RISCV][GISel] Add call preserved regmask to calls created by RISCVCallLowering::lowerCall. 2023-11-05 11:45:35 -08:00
Craig Topper
d32e801d74
[RISCV][GISel] Add FP calling convention support (#69138)
This includes support for using GPRs, FPRs, and stack.
2023-10-25 12:30:03 -07:00
Min-Yih Hsu
e696379c0d
[RISCV][GISel] Falling back to SDISel for scalable vector type values (#70133)
This patch also tests the fallback of unsupported formal arguments.
2023-10-25 09:02:34 -07:00
Craig Topper
f533e8ca9f Recommit "[RISCV][GISel] Disable call lowering for integers larger than 2*XLen. (#69144)"
Remove bad test for >2x XLen scalar. Don't restrict struct returns if they aren't homogenous.

Original commit message:
Types larger than 2*XLen are passed indirectly which is not supported
yet. Currently, we will incorrectly pass X10 multiple times.
2023-10-20 11:51:47 -07:00
Craig Topper
e103515ced
[RISCV][GISel] Support passing arguments through the stack. (#69289)
This is needed when we run out of registers.
2023-10-18 17:48:58 -07:00
Craig Topper
0ae4622126 [RISCV][GISel] Move variadic-call.ll from call-lowering directory to irtranslator. NFC
Keeps it consistent with the other call tests.
2023-10-15 18:16:38 -07:00
Nitin John Raj
9c6bee653c [RISCV][GlobalISel] Add lowerCall for calling convention
This patch implements minimal support for lowering function calls to callees with arguments and/or return values according to the RISC-V calling convention. Integer, pointer and aggregate types are supported.

Feedback is very much appreciated.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D75023
2023-06-01 15:54:25 -07:00
Nitin John Raj
af8e386102 [RISCV][GlobalISel] Add lowerFormalArguments for calling convention
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.

Coauthored By: lewis-revill

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D74977
2023-05-30 13:42:49 -07:00
Nitin John Raj
991ecfb83d [RISCV][GlobalISel] Add lowerReturn for calling conv
Add minimal support to lower return, and introduce an OutgoingValueHandler and an OutgoingValueAssigner for returns.

Supports return values with integer, pointer and aggregate types.

(Update of D69808 - avoiding commandeering that revision)

Co-authored By: lewis-revill

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D117318
2023-05-23 11:24:54 -07:00