Skip to content

Commit 3cb56d3

Browse files
committed
fixup! [RISCV] RISCV vector calling convention (2/2)
1 parent e294356 commit 3cb56d3

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20877,7 +20877,7 @@ unsigned RISCVTargetLowering::getMinimumJumpTableEntries() const {
2087720877
return Subtarget.getMinimumJumpTableEntries();
2087820878
}
2087920879

20880-
void RVVArgDispatcher::constructHelper(Type *Ty) {
20880+
void RVVArgDispatcher::constructArgInfos(Type *Ty) {
2088120881
const DataLayout &DL = MF->getDataLayout();
2088220882
const Function &F = MF->getFunction();
2088320883
LLVMContext &Context = F.getContext();
@@ -20910,16 +20910,14 @@ void RVVArgDispatcher::constructHelper(Type *Ty) {
2091020910
RegisterVT = TLI->getContainerForFixedLengthVector(RegisterVT);
2091120911

2091220912
RVVArgInfo Info{1, RegisterVT, false};
20913-
20914-
while (NumRegs--)
20915-
RVVArgInfos.push_back(Info);
20913+
RVVArgInfos.insert(RVVArgInfos.end(), NumRegs, Info);
2091620914
}
2091720915
}
2091820916
}
2091920917

20920-
void RVVArgDispatcher::construct(std::vector<Type *> &TypeList) {
20918+
void RVVArgDispatcher::construct(const std::vector<Type *> &TypeList) {
2092120919
for (Type *Ty : TypeList)
20922-
constructHelper(Ty);
20920+
constructArgInfos(Ty);
2092320921

2092420922
for (auto &Info : RVVArgInfos)
2092520923
if (Info.NF == 1 && Info.VT.getVectorElementType() == MVT::i1) {
@@ -20954,28 +20952,27 @@ void RVVArgDispatcher::allocatePhysReg(unsigned NF, unsigned LMul,
2095420952
if (StartReg)
2095520953
AllocatedPhysRegs.push_back(VRArrays[(StartReg - 8) / LMul + i]);
2095620954
else
20957-
AllocatedPhysRegs.push_back(0);
20955+
AllocatedPhysRegs.push_back(MCPhysReg());
2095820956
}
2095920957

20960-
// This function determines if each RVV argument is passed by register.
20958+
/// This function determines if each RVV argument is passed by register, if the
20959+
/// argument can be assigned to a VR, then give it a specific register.
20960+
/// Otherwise, assign the argument to 0 which is a invalid MCPhysReg.
2096120961
void RVVArgDispatcher::compute() {
20962-
unsigned ToBeAssigned = RVVArgInfos.size();
20963-
uint64_t AssignedMap = 0;
20964-
auto tryAllocate = [&](const RVVArgInfo &ArgInfo) {
20962+
uint32_t AssignedMap = 0;
20963+
auto allocate = [&](const RVVArgInfo &ArgInfo) {
2096520964
// Allocate first vector mask argument to V0.
2096620965
if (ArgInfo.FirstVMask) {
2096720966
AllocatedPhysRegs.push_back(RISCV::V0);
2096820967
return;
2096920968
}
2097020969

20971-
unsigned RegsNeeded =
20972-
std::max((unsigned)ArgInfo.VT.getSizeInBits().getKnownMinValue() /
20973-
RISCV::RVVBitsPerBlock,
20974-
(unsigned)1);
20970+
unsigned RegsNeeded = divideCeil(
20971+
ArgInfo.VT.getSizeInBits().getKnownMinValue(), RISCV::RVVBitsPerBlock);
2097520972
unsigned TotalRegsNeeded = ArgInfo.NF * RegsNeeded;
2097620973
for (unsigned StartReg = 0; StartReg + TotalRegsNeeded <= NumArgVRs;
2097720974
StartReg += RegsNeeded) {
20978-
unsigned Map = ((1 << TotalRegsNeeded) - 1) << StartReg;
20975+
uint32_t Map = ((1 << TotalRegsNeeded) - 1) << StartReg;
2097920976
if ((AssignedMap & Map) == 0) {
2098020977
allocatePhysReg(ArgInfo.NF, RegsNeeded, StartReg + 8);
2098120978
AssignedMap |= Map;
@@ -20984,11 +20981,10 @@ void RVVArgDispatcher::compute() {
2098420981
}
2098520982

2098620983
allocatePhysReg(ArgInfo.NF, RegsNeeded, 0);
20987-
return;
2098820984
};
2098920985

20990-
for (unsigned i = 0; i < ToBeAssigned; ++i)
20991-
tryAllocate(RVVArgInfos[i]);
20986+
for (unsigned i = 0; i < RVVArgInfos.size(); ++i)
20987+
allocate(RVVArgInfos[i]);
2099220988
}
2099320989

2099420990
MCPhysReg RVVArgDispatcher::getNextPhysReg() {

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,21 @@ class RISCVTargetLowering : public TargetLowering {
10121012
unsigned getMinimumJumpTableEntries() const override;
10131013
};
10141014

1015+
/// As per the spec, the rules for passing vector arguments are as follows:
1016+
///
1017+
/// 1. For the first vector mask argument, use v0 to pass it.
1018+
/// 2. For vector data arguments or rest vector mask arguments, starting from
1019+
/// the v8 register, if a vector register group between v8-v23 that has not been
1020+
/// allocated can be found and the first register number is a multiple of LMUL,
1021+
/// then allocate this vector register group to the argument and mark these
1022+
/// registers as allocated. Otherwise, pass it by reference and are replaced in
1023+
/// the argument list with the address.
1024+
/// 3. For tuple vector data arguments, starting from the v8 register, if
1025+
/// NFIELDS consecutive vector register groups between v8-v23 that have not been
1026+
/// allocated can be found and the first register number is a multiple of LMUL,
1027+
/// then allocate these vector register groups to the argument and mark these
1028+
/// registers as allocated. Otherwise, pass it by reference and are replaced in
1029+
/// the argument list with the address.
10151030
class RVVArgDispatcher {
10161031
public:
10171032
static constexpr unsigned NumArgVRs = 16;
@@ -1045,13 +1060,11 @@ class RVVArgDispatcher {
10451060

10461061
const MachineFunction *MF = nullptr;
10471062
const RISCVTargetLowering *TLI = nullptr;
1048-
TargetLowering::CallLoweringInfo *CLI = nullptr;
1049-
CallLowering::CallLoweringInfo *GISelCLI = nullptr;
10501063

10511064
unsigned CurIdx = 0;
10521065

1053-
void construct(std::vector<Type *> &TypeList);
1054-
void constructHelper(Type *Ty);
1066+
void construct(const std::vector<Type *> &TypeList);
1067+
void constructArgInfos(Type *Ty);
10551068
void compute();
10561069
void allocatePhysReg(unsigned NF = 1, unsigned LMul = 1,
10571070
unsigned StartReg = 0);

0 commit comments

Comments
 (0)