From: liushuyu Date: Thu, 1 Jun 2023 04:22:35 +0000 (-0600) Subject: gccrs: rust-compile-intrinsic: add `copy` intrinsics ... X-Git-Tag: basepoints/gcc-15~2128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9924c7485dba34fcb6200e72b9b25f9241c59cfb;p=thirdparty%2Fgcc.git gccrs: rust-compile-intrinsic: add `copy` intrinsics ... ... also made `copy_nonoverlapping` handler more generic gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc: add `copy` intrinsics and make `copy_nonoverlapping` handler more generic Signed-off-by: Zixing Liu --- diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 33ec9128cc93..420ed2dffe09 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -78,8 +78,6 @@ rotate_handler (Context *ctx, TyTy::FnType *fntype, tree_code op); static tree wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op); static tree -copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype); -static tree op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op); static tree uninit_handler (Context *ctx, TyTy::FnType *fntype); @@ -165,6 +163,17 @@ unchecked_op_handler (tree_code op) }; } +static inline tree +copy_handler_inner (Context *ctx, TyTy::FnType *fntype, bool overlaps); + +const static std::function +copy_handler (bool overlaps) +{ + return [overlaps] (Context *ctx, TyTy::FnType *fntype) { + return copy_handler_inner (ctx, fntype, overlaps); + }; +} + static inline tree expect_handler_inner (Context *ctx, TyTy::FnType *fntype, bool likely); @@ -199,7 +208,8 @@ static const std::map(src: *const T, dst: *mut T, count: usize); + * fn copy(src: *const T, dst: *mut T, count: usize); */ static tree -copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype) +copy_handler_inner (Context *ctx, TyTy::FnType *fntype, bool overlaps) { rust_assert (fntype->get_params ().size () == 3); rust_assert (fntype->get_num_substitutions () == 1); @@ -699,7 +710,7 @@ copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype) auto fndecl = compile_intrinsic_function (ctx, fntype); - // Most intrinsic functions are pure - not `copy_nonoverlapping` + // Most intrinsic functions are pure - not `copy_nonoverlapping` and `copy` TREE_READONLY (fndecl) = 0; TREE_SIDE_EFFECTS (fndecl) = 1; @@ -730,7 +741,9 @@ copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype) = build2 (MULT_EXPR, size_type_node, TYPE_SIZE_UNIT (param_type), count); tree memcpy_raw = nullptr; - BuiltinsContext::get ().lookup_simple_builtin ("memcpy", &memcpy_raw); + BuiltinsContext::get ().lookup_simple_builtin (overlaps ? "memmove" + : "memcpy", + &memcpy_raw); rust_assert (memcpy_raw); auto memcpy = build_fold_addr_expr_loc (UNKNOWN_LOCATION, memcpy_raw);