================
@@ -4052,6 +4093,44 @@ def CIR_ExpectOp : CIR_Op<"expect", [
}];
}
+//===----------------------------------------------------------------------===//
+// 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_SInt32:$result);
+
+ let assemblyFormat = [{
+ $value `:` type($value) `->` type($result) attr-dict
----------------
xlauko wrote:
@andykaylor pretty much yes. I am traying us to converge on style `: argument
types -> return types` respectivelly `: type` if the operation can be
determined by a single type. Bit of style guide is in:
https://llvm.github.io/clangir/Dialect/cir-style-guide.html
https://github.com/llvm/llvm-project/pull/166832
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits