Skip to content

Commit c94b846

Browse files
committed
fixup! [RISCV] RISCV vector calling convention (2/2)
1 parent b5b8465 commit c94b846

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
@@ -18129,7 +18129,13 @@ void RISCVTargetLowering::analyzeInputArgs(
1812918129
unsigned NumArgs = Ins.size();
1813018130
FunctionType *FType = MF.getFunction().getFunctionType();
1813118131

18132-
RVVArgDispatcher Dispatcher{&MF, this, IsRet};
18132+
std::vector<Type *> TypeList;
18133+
if (IsRet)
18134+
TypeList.push_back(MF.getFunction().getReturnType());
18135+
else
18136+
for (const Argument &Arg : MF.getFunction().args())
18137+
TypeList.push_back(Arg.getType());
18138+
RVVArgDispatcher Dispatcher{&MF, this, TypeList};
1813318139

1813418140
for (unsigned i = 0; i != NumArgs; ++i) {
1813518141
MVT ArgVT = Ins[i].VT;
@@ -18158,7 +18164,13 @@ void RISCVTargetLowering::analyzeOutputArgs(
1815818164
CallLoweringInfo *CLI, RISCVCCAssignFn Fn) const {
1815918165
unsigned NumArgs = Outs.size();
1816018166

18161-
RVVArgDispatcher Dispatcher{&MF, this, IsRet, CLI};
18167+
std::vector<Type *> TypeList;
18168+
if (IsRet)
18169+
TypeList.push_back(MF.getFunction().getReturnType());
18170+
else if (CLI)
18171+
for (const TargetLowering::ArgListEntry &Arg : CLI->getArgs())
18172+
TypeList.push_back(Arg.Ty);
18173+
RVVArgDispatcher Dispatcher{&MF, this, TypeList};
1816218174

1816318175
for (unsigned i = 0; i != NumArgs; i++) {
1816418176
MVT ArgVT = Outs[i].VT;
@@ -19061,7 +19073,8 @@ bool RISCVTargetLowering::CanLowerReturn(
1906119073
SmallVector<CCValAssign, 16> RVLocs;
1906219074
CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
1906319075

19064-
RVVArgDispatcher Dispatcher{&MF, this, true};
19076+
std::vector<Type *> TypeList = {MF.getFunction().getReturnType()};
19077+
RVVArgDispatcher Dispatcher{&MF, this, TypeList};
1906519078

1906619079
for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
1906719080
MVT VT = Outs[i].VT;
@@ -20904,20 +20917,9 @@ void RVVArgDispatcher::constructHelper(Type *Ty) {
2090420917
}
2090520918
}
2090620919

20907-
void RVVArgDispatcher::construct(bool IsRet) {
20908-
const Function &F = MF->getFunction();
20909-
20910-
if (IsRet)
20911-
constructHelper(F.getReturnType());
20912-
else if (CLI)
20913-
for (const TargetLowering::ArgListEntry &Arg : CLI->getArgs())
20914-
constructHelper(Arg.Ty);
20915-
else if (GISelCLI)
20916-
for (const CallLowering::ArgInfo &Arg : GISelCLI->OrigArgs)
20917-
constructHelper(Arg.Ty);
20918-
else
20919-
for (const Argument &Arg : F.args())
20920-
constructHelper(Arg.getType());
20920+
void RVVArgDispatcher::construct(std::vector<Type *> &TypeList) {
20921+
for (Type *Ty : TypeList)
20922+
constructHelper(Ty);
2092120923

2092220924
for (auto &Info : RVVArgInfos)
2092320925
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
@@ -1022,14 +1022,18 @@ class RVVArgDispatcher {
10221022
bool FirstVMask = false;
10231023
};
10241024

1025-
RVVArgDispatcher() = default;
10261025
RVVArgDispatcher(const MachineFunction *MF, const RISCVTargetLowering *TLI,
1027-
bool IsRet, TargetLowering::CallLoweringInfo *CLI = nullptr,
1028-
CallLowering::CallLoweringInfo *GISelCLI = nullptr)
1029-
: MF(MF), TLI(TLI), CLI(CLI), GISelCLI(GISelCLI) {
1030-
assert((!CLI || !GISelCLI) &&
1031-
"ISel and Global ISel can't co-exist at the same time");
1032-
construct(IsRet);
1026+
std::vector<Type *> &TypeList)
1027+
: MF(MF), TLI(TLI) {
1028+
construct(TypeList);
1029+
compute();
1030+
}
1031+
1032+
RVVArgDispatcher(const MachineFunction *MF, const RISCVTargetLowering *TLI,
1033+
Type *Ty)
1034+
: MF(MF), TLI(TLI) {
1035+
std::vector<Type *> TypeList = {Ty};
1036+
construct(TypeList);
10331037
compute();
10341038
}
10351039

@@ -1046,7 +1050,7 @@ class RVVArgDispatcher {
10461050

10471051
unsigned CurIdx = 0;
10481052

1049-
void construct(bool IsRet);
1053+
void construct(std::vector<Type *> &TypeList);
10501054
void constructHelper(Type *Ty);
10511055
void compute();
10521056
void allocatePhysReg(unsigned NF = 1, unsigned LMul = 1,

0 commit comments

Comments
 (0)