Skip to content

Commit fd763f8

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

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
@@ -20531,7 +20531,7 @@ unsigned RISCVTargetLowering::getMinimumJumpTableEntries() const {
2053120531
return Subtarget.getMinimumJumpTableEntries();
2053220532
}
2053320533

20534-
void RVVArgDispatcher::constructHelper(Type *Ty) {
20534+
void RVVArgDispatcher::constructArgInfos(Type *Ty) {
2053520535
const DataLayout &DL = MF->getDataLayout();
2053620536
const Function &F = MF->getFunction();
2053720537
LLVMContext &Context = F.getContext();
@@ -20564,16 +20564,14 @@ void RVVArgDispatcher::constructHelper(Type *Ty) {
2056420564
RegisterVT = TLI->getContainerForFixedLengthVector(RegisterVT);
2056520565

2056620566
RVVArgInfo Info{1, RegisterVT, false};
20567-
20568-
while (NumRegs--)
20569-
RVVArgInfos.push_back(Info);
20567+
RVVArgInfos.insert(RVVArgInfos.end(), NumRegs, Info);
2057020568
}
2057120569
}
2057220570
}
2057320571

20574-
void RVVArgDispatcher::construct(std::vector<Type *> &TypeList) {
20572+
void RVVArgDispatcher::construct(const std::vector<Type *> &TypeList) {
2057520573
for (Type *Ty : TypeList)
20576-
constructHelper(Ty);
20574+
constructArgInfos(Ty);
2057720575

2057820576
for (auto &Info : RVVArgInfos)
2057920577
if (Info.NF == 1 && Info.VT.getVectorElementType() == MVT::i1) {
@@ -20608,28 +20606,27 @@ void RVVArgDispatcher::allocatePhysReg(unsigned NF, unsigned LMul,
2060820606
if (StartReg)
2060920607
AllocatedPhysRegs.push_back(VRArrays[(StartReg - 8) / LMul + i]);
2061020608
else
20611-
AllocatedPhysRegs.push_back(0);
20609+
AllocatedPhysRegs.push_back(MCPhysReg());
2061220610
}
2061320611

20614-
// This function determines if each RVV argument is passed by register.
20612+
/// This function determines if each RVV argument is passed by register, if the
20613+
/// argument can be assigned to a VR, then give it a specific register.
20614+
/// Otherwise, assign the argument to 0 which is a invalid MCPhysReg.
2061520615
void RVVArgDispatcher::compute() {
20616-
unsigned ToBeAssigned = RVVArgInfos.size();
20617-
uint64_t AssignedMap = 0;
20618-
auto tryAllocate = [&](const RVVArgInfo &ArgInfo) {
20616+
uint32_t AssignedMap = 0;
20617+
auto allocate = [&](const RVVArgInfo &ArgInfo) {
2061920618
// Allocate first vector mask argument to V0.
2062020619
if (ArgInfo.FirstVMask) {
2062120620
AllocatedPhysRegs.push_back(RISCV::V0);
2062220621
return;
2062320622
}
2062420623

20625-
unsigned RegsNeeded =
20626-
std::max((unsigned)ArgInfo.VT.getSizeInBits().getKnownMinValue() /
20627-
RISCV::RVVBitsPerBlock,
20628-
(unsigned)1);
20624+
unsigned RegsNeeded = divideCeil(
20625+
ArgInfo.VT.getSizeInBits().getKnownMinValue(), RISCV::RVVBitsPerBlock);
2062920626
unsigned TotalRegsNeeded = ArgInfo.NF * RegsNeeded;
2063020627
for (unsigned StartReg = 0; StartReg + TotalRegsNeeded <= NumArgVRs;
2063120628
StartReg += RegsNeeded) {
20632-
unsigned Map = ((1 << TotalRegsNeeded) - 1) << StartReg;
20629+
uint32_t Map = ((1 << TotalRegsNeeded) - 1) << StartReg;
2063320630
if ((AssignedMap & Map) == 0) {
2063420631
allocatePhysReg(ArgInfo.NF, RegsNeeded, StartReg + 8);
2063520632
AssignedMap |= Map;
@@ -20638,11 +20635,10 @@ void RVVArgDispatcher::compute() {
2063820635
}
2063920636

2064020637
allocatePhysReg(ArgInfo.NF, RegsNeeded, 0);
20641-
return;
2064220638
};
2064320639

20644-
for (unsigned i = 0; i < ToBeAssigned; ++i)
20645-
tryAllocate(RVVArgInfos[i]);
20640+
for (unsigned i = 0; i < RVVArgInfos.size(); ++i)
20641+
allocate(RVVArgInfos[i]);
2064620642
}
2064720643

2064820644
MCPhysReg RVVArgDispatcher::getNextPhysReg() {

llvm/lib/Target/RISCV/RISCVISelLowering.h

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

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

10441059
const MachineFunction *MF = nullptr;
10451060
const RISCVTargetLowering *TLI = nullptr;
1046-
TargetLowering::CallLoweringInfo *CLI = nullptr;
1047-
CallLowering::CallLoweringInfo *GISelCLI = nullptr;
10481061

10491062
unsigned CurIdx = 0;
10501063

1051-
void construct(std::vector<Type *> &TypeList);
1052-
void constructHelper(Type *Ty);
1064+
void construct(const std::vector<Type *> &TypeList);
1065+
void constructArgInfos(Type *Ty);
10531066
void compute();
10541067
void allocatePhysReg(unsigned NF = 1, unsigned LMul = 1,
10551068
unsigned StartReg = 0);

0 commit comments

Comments
 (0)