[llvm] [LLVM][Tablegen] Add Default arguments support for Intrinsics in TableGen (PR #198557)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 06:41:34 PDT 2026


================
@@ -1278,6 +1278,38 @@ static bool convertIntrinsicValidType(StringRef Name,
   return false;
 }
 
+static bool upgradeIntrinsicDeclWithDefaultArgs(Function *F, Function *&NewFn) {
+  Intrinsic::ID IID = Intrinsic::lookupIntrinsicID(F->getName());
+  if (IID == Intrinsic::not_intrinsic)
+    return false;
+
+  auto [FirstDefault, Defaults] = Intrinsic::getAllDefaultArgValues(IID);
+  if (Defaults.empty())
+    return false;
+
+  // Overloaded intrinsics are out of scope for the default-arg feature
+  // and will be supported in a follow-up.
+  if (Intrinsic::isOverloaded(IID))
+    return false;
+
+  // Get the canonical full declaration for this intrinsic.
+  Function *FullDecl = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
+
+  // If the existing declaration already has all args, nothing to upgrade
+  if (F->arg_size() >= FullDecl->arg_size())
+    return false;
+
+  // Every missing trailing arg must fall within the default range
+  // [FirstDefault, FirstDefault + Defaults.size()).
+  for (unsigned Idx = F->arg_size(); Idx < FullDecl->arg_size(); ++Idx) {
----------------
jurahul wrote:

why is a loop needed here. I'd think we just want FirstMissingIndex (F->argSize()) >= FirstDefault?

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


More information about the llvm-commits mailing list