Skip to content

Commit 98a5130

Browse files
committed
fixup! [RISCV] RISCV vector calling convention (2/2)
1 parent 9ed8e4d commit 98a5130

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct RISCVOutgoingValueAssigner : public CallLowering::OutgoingValueAssigner {
3434
// Whether this is assigning args for a return.
3535
bool IsRet;
3636

37-
RVVArgDispatcher RVVDispatcher;
37+
RVVArgDispatcher &RVVDispatcher;
3838

3939
public:
4040
RISCVOutgoingValueAssigner(
@@ -408,7 +408,8 @@ bool RISCVCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
408408
SmallVector<ArgInfo, 4> SplitRetInfos;
409409
splitToValueTypes(OrigRetInfo, SplitRetInfos, DL, CC);
410410

411-
RVVArgDispatcher Dispatcher{&MF, getTLI<RISCVTargetLowering>(), true};
411+
RVVArgDispatcher Dispatcher{&MF, getTLI<RISCVTargetLowering>(),
412+
F.getReturnType()};
412413
RISCVOutgoingValueAssigner Assigner(
413414
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
414415
/*IsRet=*/true, Dispatcher);
@@ -520,6 +521,7 @@ bool RISCVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
520521
CallingConv::ID CC = F.getCallingConv();
521522

522523
SmallVector<ArgInfo, 32> SplitArgInfos;
524+
std::vector<Type *> TypeList;
523525
unsigned Index = 0;
524526
for (auto &Arg : F.args()) {
525527
// Construct the ArgInfo object from destination register and argument type.
@@ -531,10 +533,12 @@ bool RISCVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
531533
// correspondingly and appended to SplitArgInfos.
532534
splitToValueTypes(AInfo, SplitArgInfos, DL, CC);
533535

536+
TypeList.push_back(Arg.getType());
537+
534538
++Index;
535539
}
536540

537-
RVVArgDispatcher Dispatcher{&MF, getTLI<RISCVTargetLowering>(), false};
541+
RVVArgDispatcher Dispatcher{&MF, getTLI<RISCVTargetLowering>(), TypeList};
538542
RISCVIncomingValueAssigner Assigner(
539543
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
540544
/*IsRet=*/false, Dispatcher);
@@ -575,11 +579,13 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
575579

576580
SmallVector<ArgInfo, 32> SplitArgInfos;
577581
SmallVector<ISD::OutputArg, 8> Outs;
582+
std::vector<Type *> TypeList;
578583
for (auto &AInfo : Info.OrigArgs) {
579584
// Handle any required unmerging of split value types from a given VReg into
580585
// physical registers. ArgInfo objects are constructed correspondingly and
581586
// appended to SplitArgInfos.
582587
splitToValueTypes(AInfo, SplitArgInfos, DL, CC);
588+
TypeList.push_back(AInfo.Ty);
583589
}
584590

585591
// TODO: Support tail calls.
@@ -597,8 +603,7 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
597603
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
598604
Call.addRegMask(TRI->getCallPreservedMask(MF, Info.CallConv));
599605

600-
RVVArgDispatcher ArgDispatcher{&MF, getTLI<RISCVTargetLowering>(), false,
601-
nullptr, &Info};
606+
RVVArgDispatcher ArgDispatcher{&MF, getTLI<RISCVTargetLowering>(), TypeList};
602607
RISCVOutgoingValueAssigner ArgAssigner(
603608
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
604609
/*IsRet=*/false, ArgDispatcher);
@@ -629,7 +634,8 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
629634
SmallVector<ArgInfo, 4> SplitRetInfos;
630635
splitToValueTypes(Info.OrigRet, SplitRetInfos, DL, CC);
631636

632-
RVVArgDispatcher RetDispatcher{&MF, getTLI<RISCVTargetLowering>(), true};
637+
RVVArgDispatcher RetDispatcher{&MF, getTLI<RISCVTargetLowering>(),
638+
F.getReturnType()};
633639
RISCVIncomingValueAssigner RetAssigner(
634640
CC == CallingConv::Fast ? RISCV::CC_RISCV_FastCC : RISCV::CC_RISCV,
635641
/*IsRet=*/true, RetDispatcher);

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17738,7 +17738,13 @@ void RISCVTargetLowering::analyzeInputArgs(
1773817738
unsigned NumArgs = Ins.size();
1773917739
FunctionType *FType = MF.getFunction().getFunctionType();
1774017740

17741-
RVVArgDispatcher Dispatcher{&MF, this, IsRet};
17741+
std::vector<Type *> TypeList;
17742+
if (IsRet)
17743+
TypeList.push_back(MF.getFunction().getReturnType());
17744+
else
17745+
for (const Argument &Arg : MF.getFunction().args())
17746+
TypeList.push_back(Arg.getType());
17747+
RVVArgDispatcher Dispatcher{&MF, this, TypeList};
1774217748

1774317749
for (unsigned i = 0; i != NumArgs; ++i) {
1774417750
MVT ArgVT = Ins[i].VT;
@@ -17767,7 +17773,13 @@ void RISCVTargetLowering::analyzeOutputArgs(
1776717773
CallLoweringInfo *CLI, RISCVCCAssignFn Fn) const {
1776817774
unsigned NumArgs = Outs.size();
1776917775

17770-
RVVArgDispatcher Dispatcher{&MF, this, IsRet, CLI};
17776+
std::vector<Type *> TypeList;
17777+
if (IsRet)
17778+
TypeList.push_back(MF.getFunction().getReturnType());
17779+
else if (CLI)
17780+
for (const TargetLowering::ArgListEntry &Arg : CLI->getArgs())
17781+
TypeList.push_back(Arg.Ty);
17782+
RVVArgDispatcher Dispatcher{&MF, this, TypeList};
1777117783

1777217784
for (unsigned i = 0; i != NumArgs; i++) {
1777317785
MVT ArgVT = Outs[i].VT;
@@ -18670,7 +18682,8 @@ bool RISCVTargetLowering::CanLowerReturn(
1867018682
SmallVector<CCValAssign, 16> RVLocs;
1867118683
CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
1867218684

18673-
RVVArgDispatcher Dispatcher{&MF, this, true};
18685+
std::vector<Type *> TypeList = {MF.getFunction().getReturnType()};
18686+
RVVArgDispatcher Dispatcher{&MF, this, TypeList};
1867418687

1867518688
for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
1867618689
MVT VT = Outs[i].VT;
@@ -20551,20 +20564,9 @@ void RVVArgDispatcher::constructHelper(Type *Ty) {
2055120564
}
2055220565
}
2055320566

20554-
void RVVArgDispatcher::construct(bool IsRet) {
20555-
const Function &F = MF->getFunction();
20556-
20557-
if (IsRet)
20558-
constructHelper(F.getReturnType());
20559-
else if (CLI)
20560-
for (const TargetLowering::ArgListEntry &Arg : CLI->getArgs())
20561-
constructHelper(Arg.Ty);
20562-
else if (GISelCLI)
20563-
for (const CallLowering::ArgInfo &Arg : GISelCLI->OrigArgs)
20564-
constructHelper(Arg.Ty);
20565-
else
20566-
for (const Argument &Arg : F.args())
20567-
constructHelper(Arg.getType());
20567+
void RVVArgDispatcher::construct(std::vector<Type *> &TypeList) {
20568+
for (Type *Ty : TypeList)
20569+
constructHelper(Ty);
2056820570

2056920571
for (auto &Info : RVVArgInfos)
2057020572
if (Info.NF == 1 && Info.VT.getVectorElementType() == MVT::i1) {

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,14 +1061,18 @@ class RVVArgDispatcher {
10611061
bool FirstVMask = false;
10621062
};
10631063

1064-
RVVArgDispatcher() = default;
10651064
RVVArgDispatcher(const MachineFunction *MF, const RISCVTargetLowering *TLI,
1066-
bool IsRet, TargetLowering::CallLoweringInfo *CLI = nullptr,
1067-
CallLowering::CallLoweringInfo *GISelCLI = nullptr)
1068-
: MF(MF), TLI(TLI), CLI(CLI), GISelCLI(GISelCLI) {
1069-
assert((!CLI || !GISelCLI) &&
1070-
"ISel and Global ISel can't co-exist at the same time");
1071-
construct(IsRet);
1065+
std::vector<Type *> &TypeList)
1066+
: MF(MF), TLI(TLI) {
1067+
construct(TypeList);
1068+
compute();
1069+
}
1070+
1071+
RVVArgDispatcher(const MachineFunction *MF, const RISCVTargetLowering *TLI,
1072+
Type *Ty)
1073+
: MF(MF), TLI(TLI) {
1074+
std::vector<Type *> TypeList = {Ty};
1075+
construct(TypeList);
10721076
compute();
10731077
}
10741078

@@ -1085,7 +1089,7 @@ class RVVArgDispatcher {
10851089

10861090
unsigned CurIdx = 0;
10871091

1088-
void construct(bool IsRet);
1092+
void construct(std::vector<Type *> &TypeList);
10891093
void constructHelper(Type *Ty);
10901094
void compute();
10911095
void allocatePhysReg(unsigned NF = 1, unsigned LMul = 1,

0 commit comments

Comments
 (0)