@@ -331,29 +331,39 @@ def CIR_DynamicCastOp : CIR_Op<"dyn_cast"> {
331
331
// ObjSizeOp
332
332
//===----------------------------------------------------------------------===//
333
333
334
- def CIR_SizeInfoType : CIR_I32EnumAttr< "SizeInfoType", "size info type", [
335
- I32EnumAttrCase<"Min", 0, "min">,
336
- I32EnumAttrCase<"Max", 1, "max">
337
- ]>;
338
-
339
334
def CIR_ObjSizeOp : CIR_Op<"objsize", [Pure]> {
340
- let summary = "Conversion between values of different types";
335
+ let summary = "Implements llvm.objsize builtin.";
336
+ let description = [{
337
+ The `cir.objsize` operation models the behavior of the `llvm.objectsize`
338
+ builtins in Clang. It returns the number of accessible bytes past ptr.
339
+
340
+ The `kind` argument determines whether `cir.objsize` returns 0 (if
341
+ true) or -1 (if false) when the object size is unknown. Corresponds to
342
+ `llvm.objectsize`'s `min` argument.
343
+
344
+ The `dynamic` attribute determines if the value should be evaluated at
345
+ runtime. Corresponds to `llvm.objectsize`'s `dynamic` argument.
346
+
347
+ Example:
348
+
349
+ ```mlir
350
+ %size = cir.objsize min %ptr : !cir.ptr<i32> -> i64
351
+ %dsize = cir.objsize max dynamic %ptr : !cir.ptr<i32> -> i64
352
+ ```
353
+ }];
341
354
342
355
let arguments = (ins
343
356
CIR_PointerType:$ptr,
344
- CIR_SizeInfoType:$kind ,
357
+ UnitAttr:$min ,
345
358
UnitAttr:$dynamic
346
359
);
347
360
348
361
let results = (outs CIR_AnyFundamentalIntType:$result);
349
362
350
363
let assemblyFormat = [{
351
- `(`
352
- $ptr `:` type($ptr) `,`
353
- $kind
354
- (`,` `dynamic` $dynamic^)?
355
- `)`
356
- `->` type($result) attr-dict
364
+ (`min` $min^) : (`max`)?
365
+ (`dynamic` $dynamic^)?
366
+ $ptr `:` qualified(type($ptr)) `->` qualified(type($result)) attr-dict
357
367
}];
358
368
}
359
369
0 commit comments