[llvm] [RISCV] RISCV vector calling convention (2/2) (PR #79096)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 06:38:57 PST 2024


================
@@ -20543,6 +20531,121 @@ unsigned RISCVTargetLowering::getMinimumJumpTableEntries() const {
   return Subtarget.getMinimumJumpTableEntries();
 }
 
+void RVVArgDispatcher::constructArgInfos(Type *Ty) {
+  const DataLayout &DL = MF->getDataLayout();
+  const Function &F = MF->getFunction();
+  LLVMContext &Context = F.getContext();
+
+  StructType *STy = dyn_cast<StructType>(Ty);
+  if (STy && STy->containsHomogeneousScalableVectorTypes()) {
+    Type *ElemTy = STy->getTypeAtIndex(0U);
+    EVT VT = TLI->getValueType(DL, ElemTy);
+    MVT RegisterVT =
+        TLI->getRegisterTypeForCallingConv(Context, F.getCallingConv(), VT);
+
+    RVVArgInfos.push_back({STy->getNumElements(), RegisterVT, false});
+  } else {
+    SmallVector<EVT, 4> ValueVTs;
+    ComputeValueVTs(*TLI, DL, Ty, ValueVTs);
+
+    for (unsigned Value = 0, NumValues = ValueVTs.size(); Value != NumValues;
+         ++Value) {
+      EVT VT = ValueVTs[Value];
+      MVT RegisterVT =
+          TLI->getRegisterTypeForCallingConv(Context, F.getCallingConv(), VT);
+      unsigned NumRegs =
+          TLI->getNumRegistersForCallingConv(Context, F.getCallingConv(), VT);
+
+      // Skip non-RVV register type
+      if (!RegisterVT.isVector())
+        continue;
+
+      if (RegisterVT.isFixedLengthVector())
+        RegisterVT = TLI->getContainerForFixedLengthVector(RegisterVT);
+
+      RVVArgInfo Info{1, RegisterVT, false};
+      RVVArgInfos.insert(RVVArgInfos.end(), NumRegs, Info);
+    }
+  }
+}
+
+void RVVArgDispatcher::construct(const std::vector<Type *> &TypeList) {
+  for (Type *Ty : TypeList)
+    constructArgInfos(Ty);
+
+  for (auto &Info : RVVArgInfos)
----------------
michaelmaitland wrote:

It looks like `constructArgInfos(Type *)` is building an incorrect RVVArgInfo and you are fixing it here. Any way to move this logic into `constructArgInfos` so it never returns something incorrect. I think that would be more straightforward for consumers of `constructArgInfos`.

Maybe pass a boolean to `constructArgInfos` for the first `Type *` and do `IsFirstType && Info.NF == 1 && Info.VT.getVectorElementType() == MVT::i1)` check in `constructArgInfos`?

https://github.com/llvm/llvm-project/pull/79096


More information about the llvm-commits mailing list