[llvm] [NVPTX] Convert calls to indirect when call signature mismatches function signature (PR #107644)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 02:06:47 PDT 2024


================
@@ -1657,6 +1657,33 @@ LowerUnalignedLoadRetParam(SelectionDAG &DAG, SDValue &Chain, uint64_t Offset,
   return RetVal;
 }
 
+static bool shouldConvertToIndirectCall(bool IsVarArg, unsigned ParamCount,
+                                        NVPTXTargetLowering::ArgListTy &Args,
+                                        const CallBase *CB,
+                                        GlobalAddressSDNode *Func) {
+  if (!Func)
+    return false;
+  auto *CalleeFunc = dyn_cast<Function>(Func->getGlobal());
+  if (!CalleeFunc)
+    return false;
+
+  auto ActualReturnType = CalleeFunc->getReturnType();
+  if (CB->getType() != ActualReturnType)
+    return true;
+
+  if (IsVarArg)
+    return false;
+
+  auto ActualNumParams = CalleeFunc->getFunctionType()->getNumParams();
+  if (ParamCount != ActualNumParams)
+    return true;
+  for (const Argument &I : CalleeFunc->args())
+    if (I.getType() != Args[I.getArgNo()].Ty)
+      return true;
+
+  return false;
+}
----------------
nikic wrote:

This is a complex way to spell `CB->getFunctionType() != CalleeFunc->getFunctionType()`. Or even just `!CB->getCalledFunction()`.

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


More information about the llvm-commits mailing list