[llvm] [LLVM][Tablegen] Add Default arguments support for Intrinsics in TableGen (PR #198557)
Varad Rahul Kamthe via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 04:21:18 PDT 2026
================
@@ -397,38 +408,31 @@ CodeGenIntrinsic::CodeGenIntrinsic(const Record *R,
SeenDefault = true;
} else if (SeenDefault) {
PrintFatalError(TheDef->getLoc(),
- "DefaultValue missing for argument " + Twine(i) +
- ". Defaults must form a contiguous trailing block "
- "ending at the last parameter.");
+ "missing default argument on parameter " + Twine(i));
}
}
- // Validate each declared default:
- // (a) the parameter is an integer type
- // (b) the default value fits in the declared integer width
+ // Validate each declared default: must be non-negative and fit in the
+ // parameter's integer width. Values are the raw bit pattern, so a negative
+ // is written in unsigned form (e.g. i8 -1 is 255).
for (unsigned i = 0; i < ParamDefaultValues.size(); ++i) {
if (!ParamDefaultValues[i].has_value())
continue;
- const Record *ParamTy = IS.ParamTys[i];
- if (!ParamTy->isSubClassOf("LLVMType")) {
- PrintFatalError(TheDef->getLoc(),
- "DefaultValue at argument " + Twine(i) +
- " requires an integer parameter type");
- }
- const Record *VT = ParamTy->getValueAsDef("VT");
+ const Record *VT = IS.ParamTys[i]->getValueAsDef("VT");
if (!VT->getValueAsBit("isInteger")) {
PrintFatalError(TheDef->getLoc(),
- "DefaultValue at argument " + Twine(i) +
+ "default argument on parameter " + Twine(i) +
" requires an integer parameter type");
}
unsigned Width = VT->getValueAsInt("Size");
int64_t Value = *ParamDefaultValues[i];
- int64_t MaxUnsigned = (Width >= 64) ? INT64_MAX : ((1LL << Width) - 1);
- int64_t MinSigned = (Width >= 64) ? INT64_MIN : -(1LL << (Width - 1));
- if (Value < MinSigned || Value > MaxUnsigned) {
+ int64_t MaxValue =
----------------
varadk27 wrote:
Switched the value storage and table to uint64_t and used isUIntN for the width check ; also lets the casts go away. Thanks!
https://github.com/llvm/llvm-project/pull/198557
More information about the llvm-commits
mailing list