Skip to content

Commit d23ecc7

Browse files
committed
fixup! [RISCV] RISCV vector calling convention (2/2)
1 parent 22f450b commit d23ecc7

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
@@ -20524,7 +20524,7 @@ unsigned RISCVTargetLowering::getMinimumJumpTableEntries() const {
2052420524
return Subtarget.getMinimumJumpTableEntries();
2052520525
}
2052620526

20527-
void RVVArgDispatcher::constructHelper(Type *Ty) {
20527+
void RVVArgDispatcher::constructArgInfos(Type *Ty) {
2052820528
const DataLayout &DL = MF->getDataLayout();
2052920529
const Function &F = MF->getFunction();
2053020530
LLVMContext &Context = F.getContext();
@@ -20557,16 +20557,14 @@ void RVVArgDispatcher::constructHelper(Type *Ty) {
2055720557
RegisterVT = TLI->getContainerForFixedLengthVector(RegisterVT);
2055820558

2055920559
RVVArgInfo Info{1, RegisterVT, false};
20560-
20561-
while (NumRegs--)
20562-
RVVArgInfos.push_back(Info);
20560+
RVVArgInfos.insert(RVVArgInfos.end(), NumRegs, Info);
2056320561
}
2056420562
}
2056520563
}
2056620564

20567-
void RVVArgDispatcher::construct(std::vector<Type *> &TypeList) {
20565+
void RVVArgDispatcher::construct(const std::vector<Type *> &TypeList) {
2056820566
for (Type *Ty : TypeList)
20569-
constructHelper(Ty);
20567+
constructArgInfos(Ty);
2057020568

2057120569
for (auto &Info : RVVArgInfos)
2057220570
if (Info.NF == 1 && Info.VT.getVectorElementType() == MVT::i1) {
@@ -20601,28 +20599,27 @@ void RVVArgDispatcher::allocatePhysReg(unsigned NF, unsigned LMul,
2060120599
if (StartReg)
2060220600
AllocatedPhysRegs.push_back(VRArrays[(StartReg - 8) / LMul + i]);
2060320601
else
20604-
AllocatedPhysRegs.push_back(0);
20602+
AllocatedPhysRegs.push_back(MCPhysReg());
2060520603
}
2060620604

20607-
// This function determines if each RVV argument is passed by register.
20605+
/// This function determines if each RVV argument is passed by register, if the
20606+
/// argument can be assigned to a VR, then give it a specific register.
20607+
/// Otherwise, assign the argument to 0 which is a invalid MCPhysReg.
2060820608
void RVVArgDispatcher::compute() {
20609-
unsigned ToBeAssigned = RVVArgInfos.size();
20610-
uint64_t AssignedMap = 0;
20611-
auto tryAllocate = [&](const RVVArgInfo &ArgInfo) {
20609+
uint32_t AssignedMap = 0;
20610+
auto allocate = [&](const RVVArgInfo &ArgInfo) {
2061220611
// Allocate first vector mask argument to V0.
2061320612
if (ArgInfo.FirstVMask) {
2061420613
AllocatedPhysRegs.push_back(RISCV::V0);
2061520614
return;
2061620615
}
2061720616

20618-
unsigned RegsNeeded =
20619-
std::max((unsigned)ArgInfo.VT.getSizeInBits().getKnownMinValue() /
20620-
RISCV::RVVBitsPerBlock,
20621-
(unsigned)1);
20617+
unsigned RegsNeeded = divideCeil(
20618+
ArgInfo.VT.getSizeInBits().getKnownMinValue(), RISCV::RVVBitsPerBlock);
2062220619
unsigned TotalRegsNeeded = ArgInfo.NF * RegsNeeded;
2062320620
for (unsigned StartReg = 0; StartReg + TotalRegsNeeded <= NumArgVRs;
2062420621
StartReg += RegsNeeded) {
20625-
unsigned Map = ((1 << TotalRegsNeeded) - 1) << StartReg;
20622+
uint32_t Map = ((1 << TotalRegsNeeded) - 1) << StartReg;
2062620623
if ((AssignedMap & Map) == 0) {
2062720624
allocatePhysReg(ArgInfo.NF, RegsNeeded, StartReg + 8);
2062820625
AssignedMap |= Map;
@@ -20631,11 +20628,10 @@ void RVVArgDispatcher::compute() {
2063120628
}
2063220629

2063320630
allocatePhysReg(ArgInfo.NF, RegsNeeded, 0);
20634-
return;
2063520631
};
2063620632

20637-
for (unsigned i = 0; i < ToBeAssigned; ++i)
20638-
tryAllocate(RVVArgInfos[i]);
20633+
for (unsigned i = 0; i < RVVArgInfos.size(); ++i)
20634+
allocate(RVVArgInfos[i]);
2063920635
}
2064020636

2064120637
MCPhysReg RVVArgDispatcher::getNextPhysReg() {

llvm/lib/Target/RISCV/RISCVISelLowering.h

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

1054+
/// As per the spec, the rules for passing vector arguments are as follows:
1055+
///
1056+
/// 1. For the first vector mask argument, use v0 to pass it.
1057+
/// 2. For vector data arguments or rest vector mask arguments, starting from
1058+
/// the v8 register, if a vector register group between v8-v23 that has not been
1059+
/// allocated can be found and the first register number is a multiple of LMUL,
1060+
/// then allocate this vector register group to the argument and mark these
1061+
/// registers as allocated. Otherwise, pass it by reference and are replaced in
1062+
/// the argument list with the address.
1063+
/// 3. For tuple vector data arguments, starting from the v8 register, if
1064+
/// NFIELDS consecutive vector register groups between v8-v23 that have not been
1065+
/// allocated can be found and the first register number is a multiple of LMUL,
1066+
/// then allocate these vector register groups to the argument and mark these
1067+
/// registers as allocated. Otherwise, pass it by reference and are replaced in
1068+
/// the argument list with the address.
10541069
class RVVArgDispatcher {
10551070
public:
10561071
static constexpr unsigned NumArgVRs = 16;
@@ -1084,13 +1099,11 @@ class RVVArgDispatcher {
10841099

10851100
const MachineFunction *MF = nullptr;
10861101
const RISCVTargetLowering *TLI = nullptr;
1087-
TargetLowering::CallLoweringInfo *CLI = nullptr;
1088-
CallLowering::CallLoweringInfo *GISelCLI = nullptr;
10891102

10901103
unsigned CurIdx = 0;
10911104

1092-
void construct(std::vector<Type *> &TypeList);
1093-
void constructHelper(Type *Ty);
1105+
void construct(const std::vector<Type *> &TypeList);
1106+
void constructArgInfos(Type *Ty);
10941107
void compute();
10951108
void allocatePhysReg(unsigned NF = 1, unsigned LMul = 1,
10961109
unsigned StartReg = 0);

0 commit comments

Comments
 (0)