@@ -3927,13 +3927,22 @@ def CopyOp : CIR_Op<"copy",
3927
3927
}
3928
3928
3929
3929
//===----------------------------------------------------------------------===//
3930
- // MemCpyOp
3930
+ // MemCpyOp && MemMoveOp
3931
3931
//===----------------------------------------------------------------------===//
3932
3932
3933
- def MemCpyOp : CIR_Op<"libc.memcpy"> {
3934
- let arguments = (ins Arg<CIR_PointerType, "", [MemWrite]>:$dst,
3935
- Arg<CIR_PointerType, "", [MemRead]>:$src,
3936
- PrimitiveInt:$len);
3933
+ class CIR_MemCpyOp<string mnemonic>: CIR_Op<mnemonic, [AllTypesMatch<["dst", "src"]>]> {
3934
+ let arguments = (ins Arg<VoidPtr, "", [MemWrite]>:$dst,
3935
+ Arg<VoidPtr, "", [MemRead]>:$src,
3936
+ PrimitiveUInt:$len);
3937
+ let hasVerifier = 0;
3938
+
3939
+ let extraClassDeclaration = [{
3940
+ /// Returns the byte length type.
3941
+ mlir::cir::IntType getLenTy() { return getLen().getType(); }
3942
+ }];
3943
+ }
3944
+
3945
+ def MemCpyOp : CIR_MemCpyOp<"libc.memcpy"> {
3937
3946
let summary = "Equivalent to libc's `memcpy`";
3938
3947
let description = [{
3939
3948
Given two CIR pointers, `src` and `dst`, `cir.libc.memcpy` will copy `len`
@@ -3956,17 +3965,29 @@ def MemCpyOp : CIR_Op<"libc.memcpy"> {
3956
3965
$len `bytes` `from` $src `to` $dst attr-dict
3957
3966
`:` type($len) `` `,` qualified(type($src)) `->` qualified(type($dst))
3958
3967
}];
3959
- let hasVerifier = 1;
3968
+ }
3960
3969
3961
- let extraClassDeclaration = [{
3962
- /// Returns the data source pointer type.
3963
- mlir::cir::PointerType getSrcTy() { return getSrc().getType(); }
3970
+ def MemMoveOp : CIR_MemCpyOp<"libc.memmove"> {
3971
+ let summary = "Equivalent to libc's `memmove`";
3972
+ let description = [{
3973
+ Given two CIR pointers, `src` and `dst`, `cir.libc.memmove` will copy `len`
3974
+ bytes from the memory pointed by `src` to the memory pointed by `dst`.
3964
3975
3965
- /// Returns the data destination pointer type.
3966
- mlir::cir::PointerType getDstTy() { return getDst().getType(); }
3976
+ similiar to `cir.libc.memcpy` but accounts for overlapping memory.
3967
3977
3968
- /// Returns the byte length type.
3969
- mlir::cir::IntType getLenTy() { return getLen().getType(); }
3978
+ Examples:
3979
+
3980
+ ```mlir
3981
+ // Copying 2 bytes from one array to a struct:
3982
+ %2 = cir.const #cir.int<2> : !u32i
3983
+ cir.libc.memmove %2 bytes from %arr to %struct : !cir.ptr<!void>, !u64i
3984
+ ```
3985
+ }];
3986
+
3987
+
3988
+ let assemblyFormat = [{
3989
+ $len `bytes` `from` $src `to` $dst attr-dict
3990
+ `:` qualified(type($dst)) `,` type($len)
3970
3991
}];
3971
3992
}
3972
3993
0 commit comments