1616
1717include "clang/CIR/Dialect/IR/CIRDialect.td"
1818include "clang/CIR/Dialect/IR/CIRTypes.td"
19+ include "clang/CIR/Dialect/IR/CIRTypeConstraints.td"
1920include "clang/CIR/Dialect/IR/CIRAttrs.td"
2021
2122include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
@@ -297,7 +298,7 @@ def ObjSizeOp : CIR_Op<"objsize", [Pure]> {
297298
298299 let arguments = (ins CIR_PointerType:$ptr, SizeInfoType:$kind,
299300 UnitAttr:$dynamic);
300- let results = (outs PrimitiveInt :$result);
301+ let results = (outs CIR_AnyFundamentalIntType :$result);
301302
302303 let assemblyFormat = [{
303304 `(`
@@ -333,7 +334,7 @@ def PtrDiffOp : CIR_Op<"ptr_diff", [Pure, SameTypeOperands]> {
333334 ```
334335 }];
335336
336- let results = (outs PrimitiveInt :$result);
337+ let results = (outs CIR_AnyFundamentalIntType :$result);
337338 let arguments = (ins CIR_PointerType:$lhs, CIR_PointerType:$rhs);
338339
339340 let assemblyFormat = [{
@@ -361,7 +362,11 @@ def PtrStrideOp : CIR_Op<"ptr_stride",
361362 ```
362363 }];
363364
364- let arguments = (ins CIR_PointerType:$base, PrimitiveInt:$stride);
365+ let arguments = (ins
366+ CIR_PointerType:$base,
367+ CIR_AnyFundamentalIntType:$stride
368+ );
369+
365370 let results = (outs CIR_PointerType:$result);
366371
367372 let assemblyFormat = [{
@@ -492,7 +497,7 @@ def AllocaOp : CIR_Op<"alloca", [
492497 }];
493498
494499 let arguments = (ins
495- Optional<PrimitiveInt >:$dynAllocSize,
500+ Optional<CIR_AnyFundamentalIntType >:$dynAllocSize,
496501 TypeAttr:$allocaType,
497502 StrAttr:$name,
498503 UnitAttr:$init,
@@ -1033,7 +1038,7 @@ def ResumeOp : CIR_Op<"resume", [ReturnLike, Terminator,
10331038 }];
10341039
10351040 let arguments = (ins Optional<VoidPtr>:$exception_ptr,
1036- Optional<UInt32 >:$type_id,
1041+ Optional<CIR_UInt32 >:$type_id,
10371042 UnitAttr:$rethrow);
10381043 let assemblyFormat = [{
10391044 ($rethrow^)?
@@ -1585,7 +1590,7 @@ class CIR_CountZerosBitOp<string mnemonic, TypeConstraint inputTy>
15851590 }];
15861591}
15871592
1588- def BitClrsbOp : CIR_BitOp<"bit.clrsb", AnyTypeOf<[SInt32, SInt64 ]>> {
1593+ def BitClrsbOp : CIR_BitOp<"bit.clrsb", CIR_SIntOfWidths<[32, 64 ]>> {
15891594 let summary = "Get the number of leading redundant sign bits in the input";
15901595 let description = [{
15911596 Compute the number of leading redundant sign bits in the input integer.
@@ -1616,7 +1621,7 @@ def BitClrsbOp : CIR_BitOp<"bit.clrsb", AnyTypeOf<[SInt32, SInt64]>> {
16161621 }];
16171622}
16181623
1619- def BitClzOp : CIR_CountZerosBitOp<"bit.clz", AnyTypeOf<[UInt16, UInt32, UInt64 ]>> {
1624+ def BitClzOp : CIR_CountZerosBitOp<"bit.clz", CIR_UIntOfWidths<[16, 32, 64 ]>> {
16201625 let summary = "Get the number of leading 0-bits in the input";
16211626 let description = [{
16221627 Compute the number of leading 0-bits in the input.
@@ -1641,7 +1646,7 @@ def BitClzOp : CIR_CountZerosBitOp<"bit.clz", AnyTypeOf<[UInt16, UInt32, UInt64]
16411646 }];
16421647}
16431648
1644- def BitCtzOp : CIR_CountZerosBitOp<"bit.ctz", AnyTypeOf<[UInt16, UInt32, UInt64 ]>> {
1649+ def BitCtzOp : CIR_CountZerosBitOp<"bit.ctz", CIR_UIntOfWidths<[16, 32, 64 ]>> {
16451650 let summary = "Get the number of trailing 0-bits in the input";
16461651 let description = [{
16471652 Compute the number of trailing 0-bits in the input.
@@ -1667,7 +1672,7 @@ def BitCtzOp : CIR_CountZerosBitOp<"bit.ctz", AnyTypeOf<[UInt16, UInt32, UInt64]
16671672 }];
16681673}
16691674
1670- def BitFfsOp : CIR_BitOp<"bit.ffs", AnyTypeOf<[SInt32, SInt64 ]>> {
1675+ def BitFfsOp : CIR_BitOp<"bit.ffs", CIR_SIntOfWidths<[32, 64 ]>> {
16711676 let summary = "Get the position of the least significant 1-bit of input";
16721677 let description = [{
16731678 Compute the position of the least significant 1-bit of the input.
@@ -1690,7 +1695,7 @@ def BitFfsOp : CIR_BitOp<"bit.ffs", AnyTypeOf<[SInt32, SInt64]>> {
16901695 }];
16911696}
16921697
1693- def BitParityOp : CIR_BitOp<"bit.parity", AnyTypeOf<[UInt32, UInt64 ]>> {
1698+ def BitParityOp : CIR_BitOp<"bit.parity", CIR_UIntOfWidths<[32, 64 ]>> {
16941699 let summary = "Get the parity of input";
16951700 let description = [{
16961701 Compute the parity of the input. The parity of an integer is the number of
@@ -1713,7 +1718,7 @@ def BitParityOp : CIR_BitOp<"bit.parity", AnyTypeOf<[UInt32, UInt64]>> {
17131718}
17141719
17151720def BitPopcountOp
1716- : CIR_BitOp<"bit.popcount", AnyTypeOf<[UInt16, UInt32, UInt64 ]>> {
1721+ : CIR_BitOp<"bit.popcount", CIR_UIntOfWidths<[16, 32, 64 ]>> {
17171722 let summary = "Get the number of 1-bits in input";
17181723 let description = [{
17191724 Compute the number of 1-bits in the input.
@@ -1760,7 +1765,7 @@ def ByteswapOp : CIR_Op<"bswap", [Pure, SameOperandsAndResultType]> {
17601765 }];
17611766
17621767 let results = (outs CIR_IntType:$result);
1763- let arguments = (ins AnyTypeOf<[UInt16, UInt32, UInt64 ]>:$input);
1768+ let arguments = (ins CIR_UIntOfWidths<[16, 32, 64 ]>:$input);
17641769
17651770 let assemblyFormat = [{
17661771 `(` $input `:` type($input) `)` `:` type($result) attr-dict
@@ -1792,7 +1797,7 @@ def RotateOp : CIR_Op<"rotate", [Pure, SameOperandsAndResultType]> {
17921797 }];
17931798
17941799 let results = (outs CIR_IntType:$result);
1795- let arguments = (ins PrimitiveInt :$src, PrimitiveInt :$amt,
1800+ let arguments = (ins CIR_IntType :$src, CIR_IntType :$amt,
17961801 UnitAttr:$left);
17971802
17981803 let assemblyFormat = [{
@@ -1821,8 +1826,8 @@ def BitReverseOp : CIR_Op<"bit_reverse", [Pure, SameOperandsAndResultType]> {
18211826 ```
18221827 }];
18231828
1824- let arguments = (ins AnyTypeOf<[UInt8, UInt16, UInt32, UInt64 ]>:$src);
1825- let results = (outs AnyTypeOf<[UInt8, UInt16, UInt32, UInt64 ]>:$result);
1829+ let arguments = (ins CIR_UIntOfWidths<[8, 16, 32, 64 ]>:$src);
1830+ let results = (outs CIR_UIntOfWidths<[8, 16, 32, 64 ]>:$result);
18261831
18271832 let assemblyFormat = [{
18281833 $src `:` type($result) attr-dict
@@ -1868,7 +1873,7 @@ def CmpThreeWayOp : CIR_Op<"cmp3way", [Pure, SameTypeOperands]> {
18681873 ```
18691874 }];
18701875
1871- let results = (outs PrimitiveSInt :$result);
1876+ let results = (outs CIR_AnySIntType :$result);
18721877 let arguments = (ins CIR_AnyType:$lhs, CIR_AnyType:$rhs,
18731878 CmpThreeWayInfoAttr:$info);
18741879
@@ -3134,7 +3139,12 @@ def VecInsertOp : CIR_Op<"vec.insert", [Pure,
31343139 element is returned.
31353140 }];
31363141
3137- let arguments = (ins CIR_VectorType:$vec, AnyType:$value, PrimitiveInt:$index);
3142+ let arguments = (ins
3143+ CIR_VectorType:$vec,
3144+ AnyType:$value,
3145+ CIR_AnyFundamentalIntType:$index
3146+ );
3147+
31383148 let results = (outs CIR_VectorType:$result);
31393149
31403150 let assemblyFormat = [{
@@ -3161,7 +3171,11 @@ def VecExtractOp : CIR_Op<"vec.extract", [Pure,
31613171 from a vector object.
31623172 }];
31633173
3164- let arguments = (ins CIR_VectorType:$vec, PrimitiveInt:$index);
3174+ let arguments = (ins
3175+ CIR_VectorType:$vec,
3176+ CIR_AnyFundamentalIntType:$index
3177+ );
3178+
31653179 let results = (outs CIR_AnyType:$result);
31663180
31673181 let assemblyFormat = [{
@@ -4367,7 +4381,7 @@ def EhInflightOp : CIR_Op<"eh.inflight_exception"> {
43674381
43684382 let arguments = (ins UnitAttr:$cleanup,
43694383 OptionalAttr<FlatSymbolRefArrayAttr>:$sym_type_list);
4370- let results = (outs VoidPtr:$exception_ptr, UInt32 :$type_id);
4384+ let results = (outs VoidPtr:$exception_ptr, CIR_UInt32 :$type_id);
43714385 let assemblyFormat = [{
43724386 (`cleanup` $cleanup^)?
43734387 ($sym_type_list^)?
@@ -4386,7 +4400,7 @@ def EhTypeIdOp : CIR_Op<"eh.typeid",
43864400 }];
43874401
43884402 let arguments = (ins FlatSymbolRefAttr:$type_sym);
4389- let results = (outs UInt32 :$type_id);
4403+ let results = (outs CIR_UInt32 :$type_id);
43904404 let assemblyFormat = [{
43914405 $type_sym attr-dict
43924406 }];
@@ -4469,7 +4483,7 @@ def MemCpyOp : CIR_MemOp<"libc.memcpy"> {
44694483 ```
44704484 }];
44714485
4472- let arguments = !con(commonArgs, (ins PrimitiveUInt :$len));
4486+ let arguments = !con(commonArgs, (ins CIR_AnyFundamentalUIntType :$len));
44734487
44744488 let assemblyFormat = [{
44754489 $len `bytes` `from` $src `to` $dst attr-dict
@@ -4499,7 +4513,7 @@ def MemMoveOp : CIR_MemOp<"libc.memmove"> {
44994513 ```
45004514 }];
45014515
4502- let arguments = !con(commonArgs, (ins PrimitiveUInt :$len));
4516+ let arguments = !con(commonArgs, (ins CIR_AnyFundamentalUIntType :$len));
45034517
45044518 let assemblyFormat = [{
45054519 $len `bytes` `from` $src `to` $dst attr-dict
@@ -4547,9 +4561,6 @@ def MemCpyInlineOp : CIR_MemOp<"memcpy_inline"> {
45474561//===----------------------------------------------------------------------===//
45484562
45494563def MemSetOp : CIR_Op<"libc.memset"> {
4550- let arguments = (ins Arg<VoidPtr, "", [MemWrite]>:$dst,
4551- SInt32:$val,
4552- PrimitiveUInt:$len);
45534564 let summary = "Equivalent to libc's `memset`";
45544565 let description = [{
45554566 Given the CIR pointer, `dst`, `cir.libc.memset` will set the first `len`
@@ -4566,21 +4577,23 @@ def MemSetOp : CIR_Op<"libc.memset"> {
45664577 ```
45674578 }];
45684579
4580+ let arguments = (ins
4581+ Arg<VoidPtr, "", [MemWrite]>:$dst,
4582+ CIR_SInt32:$val,
4583+ CIR_AnyFundamentalUIntType:$len
4584+ );
4585+
45694586 let assemblyFormat = [{
45704587 $len `bytes` `from` $dst `set` `to` $val attr-dict
45714588 `:` qualified(type($dst)) `,` type($val) `,` type($len)
45724589 }];
4573- let hasVerifier = 0;
45744590}
45754591
45764592//===----------------------------------------------------------------------===//
45774593// MemSetInlineOp
45784594//===----------------------------------------------------------------------===//
45794595
45804596def MemSetInlineOp : CIR_Op<"memset_inline"> {
4581- let arguments = (ins Arg<VoidPtr, "", [MemWrite]>:$dst,
4582- SInt32:$val,
4583- I64Attr:$len);
45844597 let summary = "Fill a block of memory with constant length without calling"
45854598 "any external function";
45864599 let description = [{
@@ -4598,25 +4611,24 @@ def MemSetInlineOp : CIR_Op<"memset_inline"> {
45984611 ```
45994612 }];
46004613
4614+ let arguments = (ins
4615+ Arg<VoidPtr, "", [MemWrite]>:$dst,
4616+ CIR_SInt32:$val,
4617+ I64Attr:$len
4618+ );
4619+
46014620 let assemblyFormat = [{
46024621 $len `bytes` `from` $dst `set` `to` $val attr-dict
46034622 `:` qualified(type($dst)) `,` type($val)
46044623 }];
4605- let hasVerifier = 0;
46064624}
4625+
46074626//===----------------------------------------------------------------------===//
46084627// MemChrOp
46094628//===----------------------------------------------------------------------===//
46104629
46114630def MemChrOp : CIR_Op<"libc.memchr"> {
4612- // TODO: instead of using UInt64 for len, we could make it constrained on
4613- // size_t (64 or 32) and have a builder that does the right job.
4614- let arguments = (ins Arg<VoidPtr, "", [MemRead]>:$src,
4615- SInt32:$pattern,
4616- UInt64:$len);
46174631 let summary = "libc's `memchr`";
4618- let results = (outs Res<VoidPtr, "">:$result);
4619-
46204632 let description = [{
46214633 Search for `pattern` in data range from `src` to `src` + `len`.
46224634 provides a bound to the search in `src`. `result` is a pointer to found
@@ -4629,24 +4641,32 @@ def MemChrOp : CIR_Op<"libc.memchr"> {
46294641 ```
46304642 }];
46314643
4644+ // TODO: instead of using UInt64 for len, we could make it constrained on
4645+ // size_t (64 or 32) and have a builder that does the right job.
4646+ let arguments = (ins
4647+ Arg<VoidPtr, "", [MemRead]>:$src,
4648+ CIR_SInt32:$pattern,
4649+ CIR_UInt64:$len
4650+ );
4651+
4652+ let results = (outs Res<VoidPtr, "">:$result);
4653+
46324654 let assemblyFormat = [{
46334655 `(`
46344656 $src `,` $pattern `,` $len `)` attr-dict
46354657 }];
4636- let hasVerifier = 0;
46374658}
46384659
46394660//===----------------------------------------------------------------------===//
46404661// ReturnAddrOp and FrameAddrOp
46414662//===----------------------------------------------------------------------===//
46424663
46434664class FuncAddrBuiltinOp<string mnemonic> : CIR_Op<mnemonic, []> {
4644- let arguments = (ins UInt32 :$level);
4665+ let arguments = (ins CIR_UInt32 :$level);
46454666 let results = (outs Res<VoidPtr, "">:$result);
46464667 let assemblyFormat = [{
46474668 `(` $level `)` attr-dict
46484669 }];
4649- let hasVerifier = 0;
46504670}
46514671
46524672def ReturnAddrOp : FuncAddrBuiltinOp<"return_address"> {
@@ -4951,10 +4971,14 @@ def ExpectOp : CIR_Op<"expect",
49514971 where probability = $prob.
49524972 }];
49534973
4954- let arguments = (ins PrimitiveInt:$val,
4955- PrimitiveInt:$expected,
4956- OptionalAttr<F64Attr>:$prob);
4957- let results = (outs PrimitiveInt:$result);
4974+ let arguments = (ins
4975+ CIR_AnyFundamentalIntType:$val,
4976+ CIR_AnyFundamentalIntType:$expected,
4977+ OptionalAttr<F64Attr>:$prob
4978+ );
4979+
4980+ let results = (outs CIR_AnyFundamentalIntType:$result);
4981+
49584982 let assemblyFormat = [{
49594983 `(` $val`,` $expected (`,` $prob^)? `)` `:` type($val) attr-dict
49604984 }];
0 commit comments