[clang] feat: included support for is_constant builtin (PR #166832)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 11 01:50:37 PST 2025
================
@@ -3043,6 +3043,44 @@ def CIR_ArrayDtor : CIR_ArrayInitDestroy<"array.dtor"> {
}];
}
+//===----------------------------------------------------------------------===//
+// IsConstantOp
+//===----------------------------------------------------------------------===//
+
+def CIR_IsConstantOp : CIR_Op<"is_constant", [Pure]> {
+ let summary = "Check if a value is a compile-time constant";
+ let description = [{
+ The `cir.is_constant` operation checks whether its input value is a
+ compile-time constant. This operation models the `__builtin_constant_p`
+ builtin function.
+
+ The operation takes a single operand of any CIR type and returns a signed
+ 32-bit integer. The result is 1 if the operand is a compile-time constant,
+ and 0 otherwise.
+
+ If the value can be determined to be constant at compile time, this
+ operation may be folded to a constant value. Otherwise, it will be lowered
+ to the `llvm.is.constant` intrinsic.
+
+ Example:
+
+ ```mlir
+ %0 = cir.is_constant %expr : i32 -> !s32i
+ %1 = cir.is_constant %ptr : !cir.ptr<i32> -> !s32i
+ ```
+ }];
+
+ let arguments = (ins CIR_AnyType:$value);
+ let results = (outs CIR_BoolType:$result);
+
+ let assemblyFormat = [{
+ `(` $value `:` type($value) `)` `:` type($result) attr-dict
+ }];
+
+ // let hasFolder = 1;
----------------
xlauko wrote:
Remove this or implement folder as well.
https://github.com/llvm/llvm-project/pull/166832
More information about the cfe-commits
mailing list