14
14
15
15
#include " RISCVCallLowering.h"
16
16
#include " RISCVISelLowering.h"
17
+ #include " RISCVMachineFunctionInfo.h"
17
18
#include " RISCVSubtarget.h"
18
19
#include " llvm/CodeGen/Analysis.h"
19
20
#include " llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
@@ -185,6 +186,9 @@ struct RISCVIncomingValueAssigner : public CallLowering::IncomingValueAssigner {
185
186
const DataLayout &DL = MF.getDataLayout ();
186
187
const RISCVSubtarget &Subtarget = MF.getSubtarget <RISCVSubtarget>();
187
188
189
+ if (LocVT.isScalableVector ())
190
+ MF.getInfo <RISCVMachineFunctionInfo>()->setIsVectorCall ();
191
+
188
192
if (RISCVAssignFn (DL, Subtarget.getTargetABI (), ValNo, ValVT, LocVT,
189
193
LocInfo, Flags, State, /* IsFixed=*/ true , IsRet, Info.Ty ,
190
194
*Subtarget.getTargetLowering (),
@@ -301,8 +305,31 @@ struct RISCVCallReturnHandler : public RISCVIncomingValueHandler {
301
305
RISCVCallLowering::RISCVCallLowering (const RISCVTargetLowering &TLI)
302
306
: CallLowering(&TLI) {}
303
307
308
+ // / Return true if scalable vector with ScalarTy is legal for lowering.
309
+ static bool isLegalElementTypeForRVV (Type *EltTy,
310
+ const RISCVSubtarget &Subtarget) {
311
+ if (EltTy->isPointerTy ())
312
+ return Subtarget.is64Bit () ? Subtarget.hasVInstructionsI64 () : true ;
313
+ if (EltTy->isIntegerTy (1 ) || EltTy->isIntegerTy (8 ) ||
314
+ EltTy->isIntegerTy (16 ) || EltTy->isIntegerTy (32 ))
315
+ return true ;
316
+ if (EltTy->isIntegerTy (64 ))
317
+ return Subtarget.hasVInstructionsI64 ();
318
+ if (EltTy->isHalfTy ())
319
+ return Subtarget.hasVInstructionsF16 ();
320
+ if (EltTy->isBFloatTy ())
321
+ return Subtarget.hasVInstructionsBF16 ();
322
+ if (EltTy->isFloatTy ())
323
+ return Subtarget.hasVInstructionsF32 ();
324
+ if (EltTy->isDoubleTy ())
325
+ return Subtarget.hasVInstructionsF64 ();
326
+ return false ;
327
+ }
328
+
304
329
// TODO: Support all argument types.
305
- static bool isSupportedArgumentType (Type *T, const RISCVSubtarget &Subtarget) {
330
+ // TODO: Remove IsLowerArgs argument by adding support for vectors in lowerCall.
331
+ static bool isSupportedArgumentType (Type *T, const RISCVSubtarget &Subtarget,
332
+ bool IsLowerArgs = false ) {
306
333
// TODO: Integers larger than 2*XLen are passed indirectly which is not
307
334
// supported yet.
308
335
if (T->isIntegerTy ())
@@ -311,6 +338,11 @@ static bool isSupportedArgumentType(Type *T, const RISCVSubtarget &Subtarget) {
311
338
return true ;
312
339
if (T->isPointerTy ())
313
340
return true ;
341
+ // TODO: Support fixed vector types.
342
+ if (IsLowerArgs && T->isVectorTy () && Subtarget.hasVInstructions () &&
343
+ T->isScalableTy () &&
344
+ isLegalElementTypeForRVV (T->getScalarType (), Subtarget))
345
+ return true ;
314
346
return false ;
315
347
}
316
348
@@ -398,7 +430,8 @@ bool RISCVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
398
430
const RISCVSubtarget &Subtarget =
399
431
MIRBuilder.getMF ().getSubtarget <RISCVSubtarget>();
400
432
for (auto &Arg : F.args ()) {
401
- if (!isSupportedArgumentType (Arg.getType (), Subtarget))
433
+ if (!isSupportedArgumentType (Arg.getType (), Subtarget,
434
+ /* IsLowerArgs=*/ true ))
402
435
return false ;
403
436
}
404
437
0 commit comments