[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:42:07 PDT 2026
================
@@ -4983,6 +5013,55 @@ static Value *upgradeConvertIntrinsicCall(StringRef Name, CallBase *CI,
return nullptr;
}
+static bool upgradeIntrinsicCallWithDefaultArgs(CallBase *CI, Function *NewFn,
+ IRBuilder<> &Builder) {
+ Intrinsic::ID IID = NewFn->getIntrinsicID();
+
+ auto [FirstDefault, Defaults] = Intrinsic::getAllDefaultArgValues(IID);
+ if (Defaults.empty())
+ return false;
+
+ unsigned OldArgCount = CI->arg_size();
+ unsigned NewArgCount = NewFn->arg_size();
+
+ // If the caller already supplied all arguments (or more), nothing to do.
+ // This mirrors C++ semantics: an explicitly-passed value is never overridden.
+ if (OldArgCount >= NewArgCount)
+ return false;
+
+ // Start with the existing arguments from the old call.
+ SmallVector<Value *, 8> NewArgs(CI->args());
+
+ // Fill in each missing trailing argument from the table.
+ FunctionType *NewFT = NewFn->getFunctionType();
+ for (unsigned Idx = OldArgCount; Idx < NewArgCount; ++Idx) {
+ if (Idx < FirstDefault || Idx >= FirstDefault + Defaults.size())
----------------
jurahul wrote:
should this be assert instead?
https://github.com/llvm/llvm-project/pull/198557
More information about the llvm-commits
mailing list