[llvm] [NVPTX][NFC] Refactoring and cleanup in NVPTXISelLowering (PR #137222)

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 24 14:47:42 PDT 2025


================
@@ -3388,49 +3373,55 @@ SDValue NVPTXTargetLowering::LowerFormalArguments(
   //     individually present in Ins.
   // So a different index should be used for indexing into Ins.
   // See similar issue in LowerCall.
-  unsigned InsIdx = 0;
+  const auto *In = Ins.begin();
 
-  for (unsigned i = 0, e = theArgs.size(); i != e; ++i, ++InsIdx) {
-    Type *Ty = argTypes[i];
+  for (const auto &Arg : F->args()) {
+    Type *Ty = Arg.getType();
 
-    if (theArgs[i]->use_empty()) {
-      // argument is dead
-      if (shouldPassAsArray(Ty) && !Ty->isVectorTy()) {
-        SmallVector<EVT, 16> vtparts;
+    if (In == Ins.end() || In->OrigArgIndex != Arg.getArgNo())
+      report_fatal_error("Empty parameter types are not supported");
 
-        ComputePTXValueVTs(*this, DAG.getDataLayout(), Ty, vtparts);
-        if (vtparts.empty())
-          report_fatal_error("Empty parameter types are not supported");
-
-        for (unsigned parti = 0, parte = vtparts.size(); parti != parte;
-             ++parti) {
-          InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
-          ++InsIdx;
-        }
-        if (vtparts.size() > 0)
-          --InsIdx;
-        continue;
-      }
-      if (Ty->isVectorTy()) {
-        EVT ObjectVT = getValueType(DL, Ty);
-        unsigned NumRegs = TLI->getNumRegisters(F->getContext(), ObjectVT);
-        for (unsigned parti = 0; parti < NumRegs; ++parti) {
-          InVals.push_back(DAG.getNode(ISD::UNDEF, dl, Ins[InsIdx].VT));
-          ++InsIdx;
-        }
-        if (NumRegs > 0)
-          --InsIdx;
-        continue;
+    if (Arg.use_empty()) {
+      // argument is dead
+      for (; In != Ins.end() && In->OrigArgIndex == Arg.getArgNo(); ++In) {
----------------
AlexMaclean wrote:

I don't think this would work since we want to update `In` to move past this argument. 

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


More information about the llvm-commits mailing list