aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-10-26 16:06:53 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2023-02-21 12:36:43 +0100
commitcb2cf21cf336cfcb12a7e814e816310a8f2a177e (patch)
tree7a02c711726b69eccbfbebe1030e9d5c0bb680ac
parent1c586a1d1c12dce2a65fb117b577a73ad5cf45ea (diff)
downloadgcc-cb2cf21cf336cfcb12a7e814e816310a8f2a177e.zip
gcc-cb2cf21cf336cfcb12a7e814e816310a8f2a177e.tar.gz
gcc-cb2cf21cf336cfcb12a7e814e816310a8f2a177e.tar.bz2
gccrs: intrinsics: Use lambdas for wrapping_<op> intrinsics
gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (wrapping_op_handler): Refactor to return an `std::function`. (wrapping_op_handler_inner): Rename. (wrapping_add_handler): Remove function. (wrapping_sub_handler): Likewise. (wrapping_mul_handler): Likewise.
-rw-r--r--gcc/rust/backend/rust-compile-intrinsic.cc29
1 files changed, 11 insertions, 18 deletions
diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc
index 46ea5b3..142a217 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -59,7 +59,7 @@ transmute_handler (Context *ctx, TyTy::FnType *fntype);
static tree
rotate_handler (Context *ctx, TyTy::FnType *fntype, tree_code op);
static tree
-wrapping_op_handler (Context *ctx, TyTy::FnType *fntype, tree_code op);
+wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op);
static tree
copy_nonoverlapping_handler (Context *ctx, TyTy::FnType *fntype);
@@ -83,21 +83,14 @@ rotate_right_handler (Context *ctx, TyTy::FnType *fntype)
return rotate_handler (ctx, fntype, RROTATE_EXPR);
}
-static inline tree
-wrapping_add_handler (Context *ctx, TyTy::FnType *fntype)
-{
- return wrapping_op_handler (ctx, fntype, PLUS_EXPR);
-}
-static inline tree
-wrapping_sub_handler (Context *ctx, TyTy::FnType *fntype)
-{
- return wrapping_op_handler (ctx, fntype, MINUS_EXPR);
-}
-static inline tree
-wrapping_mul_handler (Context *ctx, TyTy::FnType *fntype)
+const static std::function<tree (Context *, TyTy::FnType *)>
+wrapping_op_handler (tree_code op)
{
- return wrapping_op_handler (ctx, fntype, MULT_EXPR);
+ return [op] (Context *ctx, TyTy::FnType *fntype) {
+ return wrapping_op_handler_inner (ctx, fntype, op);
+ };
}
+
static inline tree
prefetch_read_data (Context *ctx, TyTy::FnType *fntype)
{
@@ -148,9 +141,9 @@ static const std::map<std::string,
{"transmute", transmute_handler},
{"rotate_left", rotate_left_handler},
{"rotate_right", rotate_right_handler},
- {"wrapping_add", wrapping_add_handler},
- {"wrapping_sub", wrapping_sub_handler},
- {"wrapping_mul", wrapping_mul_handler},
+ {"wrapping_add", wrapping_op_handler (PLUS_EXPR)},
+ {"wrapping_sub", wrapping_op_handler (MINUS_EXPR)},
+ {"wrapping_mul", wrapping_op_handler (MULT_EXPR)},
{"copy_nonoverlapping", copy_nonoverlapping_handler},
{"prefetch_read_data", prefetch_read_data},
{"prefetch_write_data", prefetch_write_data},
@@ -493,7 +486,7 @@ rotate_handler (Context *ctx, TyTy::FnType *fntype, tree_code op)
* pub fn wrapping_{add, sub, mul}<T>(lhs: T, rhs: T) -> T;
*/
static tree
-wrapping_op_handler (Context *ctx, TyTy::FnType *fntype, tree_code op)
+wrapping_op_handler_inner (Context *ctx, TyTy::FnType *fntype, tree_code op)
{
// wrapping_<op> intrinsics have two parameter
rust_assert (fntype->get_params ().size () == 2);