aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-10-27 10:19:47 +0000
committerGitHub <noreply@github.com>2022-10-27 10:19:47 +0000
commit4dbff3d0550fed53de385ff5a52859178f8940cc (patch)
treee273088dfe67ab85debafb5c9fc2b321c6000df8 /gcc
parentd8a8061f2e884aa2aa31d746c4cc104083bbbbb6 (diff)
parent2357b5d5138a926d7b3f054aa66549482bec9be6 (diff)
downloadgcc-4dbff3d0550fed53de385ff5a52859178f8940cc.zip
gcc-4dbff3d0550fed53de385ff5a52859178f8940cc.tar.gz
gcc-4dbff3d0550fed53de385ff5a52859178f8940cc.tar.bz2
Merge #1621
1621: intrinsics: Use lambdas for wrapping_<op> intrinsics r=CohenArthur a=CohenArthur Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc')
-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 7c592da..8c6fbd7 100644
--- a/gcc/rust/backend/rust-compile-intrinsic.cc
+++ b/gcc/rust/backend/rust-compile-intrinsic.cc
@@ -43,7 +43,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);
@@ -67,21 +67,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)
+const static std::function<tree (Context *, TyTy::FnType *)>
+wrapping_op_handler (tree_code op)
{
- 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)
-{
- 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)
{
@@ -121,9 +114,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},
@@ -459,7 +452,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);