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

Kevin McAfee via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 11:57:50 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;
+}
----------------
kalxr wrote:

`CB->getCalledFunction()` is a bit different because `CB->getCalledOperand()` cannot be casted to a function in every case where `Func->getGlobal()` can. NVPTX/alias.ll has a case of this with the function pointer aliasing. Comparing the types directly makes sense though, thanks for the suggestion.

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


More information about the llvm-commits mailing list