[Mlir-commits] [llvm] [mlir] [LLVM] Refactor intrinsic validation (PR #194061)

Rahul Joshi llvmlistbot at llvm.org
Thu Apr 30 09:13:54 PDT 2026


================
@@ -1088,77 +1084,90 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
   llvm_unreachable("unhandled");
 }
 
-Intrinsic::MatchIntrinsicTypesResult
-Intrinsic::matchIntrinsicSignature(FunctionType *FTy,
-                                   ArrayRef<Intrinsic::IITDescriptor> &Infos,
-                                   SmallVectorImpl<Type *> &OverloadTys) {
+/// Returns true if the intrinsic is a VarArg intrinsics. If \p Consume is true
+/// the IITDescriptor for the VarArg is consumed and removed from \p Infos, else
+/// it stays unchanged.
+static bool isIntrinsicVarArg(ArrayRef<Intrinsic::IITDescriptor> &Infos,
+                              bool Consume) {
+  if (!Infos.empty() && Infos.back().Kind == Intrinsic::IITDescriptor::VarArg) {
+    if (Consume)
+      Infos.consume_back();
+    return true;
+  }
+  return false;
+}
+
+bool Intrinsic::matchIntrinsicSignature(
+    FunctionType *FTy, ArrayRef<Intrinsic::IITDescriptor> &Infos,
+    SmallVectorImpl<Type *> &OverloadTys, raw_ostream &OS) {
+  bool IsVarArg = isIntrinsicVarArg(Infos, /*Consume=*/true);
+
   SmallVector<DeferredIntrinsicMatchPair, 2> DeferredChecks;
   if (matchIntrinsicType(FTy->getReturnType(), Infos, OverloadTys,
-                         DeferredChecks, false))
-    return MatchIntrinsicTypes_NoMatchRet;
+                         DeferredChecks, false)) {
+    OS << "intrinsic has incorrect return type!";
+    return true;
+  }
 
   unsigned NumDeferredReturnChecks = DeferredChecks.size();
 
-  for (auto *Ty : FTy->params())
-    if (matchIntrinsicType(Ty, Infos, OverloadTys, DeferredChecks, false))
-      return MatchIntrinsicTypes_NoMatchArg;
+  for (Type *Ty : FTy->params())
----------------
jurahul wrote:

Need: no. But per-LLVM CS or generally accepted convention, use of auto is OK when the inferred type is obvious (like in case of cast or dyn_cast where it's mentioned in the RHS of the assignment) or is too long to spell explicitly (like iterator types). In other cases, it's preferred to use the actual type explicitly, so that's what this code is doing.

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


More information about the Mlir-commits mailing list