Skip to content

Commit 31f4fbb

Browse files
committed
gccrs: Add move_val_init intrinsic
TODO Fixes #1902 gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (move_val_init_handler): (uninit_handler): Signed-off-by: Philip Herron <[email protected]>
1 parent e28c009 commit 31f4fbb

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

gcc/rust/backend/rust-compile-intrinsic.cc

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ static tree
8383
op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op);
8484
static tree
8585
uninit_handler (Context *ctx, TyTy::FnType *fntype);
86+
static tree
87+
move_val_init_handler (Context *ctx, TyTy::FnType *fntype);
8688

8789
enum class Prefetch
8890
{
@@ -205,6 +207,7 @@ static const std::map<std::string,
205207
{"unchecked_shl", unchecked_op_handler (LSHIFT_EXPR)},
206208
{"unchecked_shr", unchecked_op_handler (RSHIFT_EXPR)},
207209
{"uninit", uninit_handler},
210+
{"move_val_init", move_val_init_handler},
208211
};
209212

210213
Intrinsics::Intrinsics (Context *ctx) : ctx (ctx) {}
@@ -1001,7 +1004,7 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
10011004

10021005
auto fndecl = compile_intrinsic_function (ctx, fntype);
10031006

1004-
// get the template parameter type tree fn size_of<T>();
1007+
// get the template parameter type tree fn uninit<T>();
10051008
rust_assert (fntype->get_num_substitutions () == 1);
10061009
auto &param_mapping = fntype->get_substs ().at (0);
10071010
const TyTy::ParamType *param_tyty = param_mapping.get_param_ty ();
@@ -1042,5 +1045,56 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype)
10421045
return fndecl;
10431046
}
10441047

1048+
static tree
1049+
move_val_init_handler (Context *ctx, TyTy::FnType *fntype)
1050+
{
1051+
rust_assert (fntype->get_params ().size () == 2);
1052+
1053+
tree lookup = NULL_TREE;
1054+
if (check_for_cached_intrinsic (ctx, fntype, &lookup))
1055+
return lookup;
1056+
1057+
auto fndecl = compile_intrinsic_function (ctx, fntype);
1058+
1059+
// get the template parameter type tree fn size_of<T>();
1060+
rust_assert (fntype->get_num_substitutions () == 1);
1061+
auto &param_mapping = fntype->get_substs ().at (0);
1062+
const TyTy::ParamType *param_tyty = param_mapping.get_param_ty ();
1063+
TyTy::BaseType *resolved_tyty = param_tyty->resolve ();
1064+
tree template_parameter_type
1065+
= TyTyResolveCompile::compile (ctx, resolved_tyty);
1066+
1067+
std::vector<Bvariable *> param_vars;
1068+
compile_fn_params (ctx, fntype, fndecl, &param_vars);
1069+
1070+
if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars))
1071+
return error_mark_node;
1072+
1073+
enter_intrinsic_block (ctx, fndecl);
1074+
1075+
// BUILTIN size_of FN BODY BEGIN
1076+
1077+
tree dst = ctx->get_backend ()->var_expression (param_vars[0], Location ());
1078+
tree src = ctx->get_backend ()->var_expression (param_vars[1], Location ());
1079+
tree size = TYPE_SIZE_UNIT (template_parameter_type);
1080+
1081+
tree memcpy_builtin = error_mark_node;
1082+
BuiltinsContext::get ().lookup_simple_builtin ("memcpy", &memcpy_builtin);
1083+
rust_assert (memcpy_builtin != error_mark_node);
1084+
1085+
src = build_fold_addr_expr_loc (BUILTINS_LOCATION, src);
1086+
tree memset_call = build_call_expr_loc (BUILTINS_LOCATION, memcpy_builtin, 3,
1087+
dst, src, size);
1088+
TREE_READONLY (memset_call) = 0;
1089+
TREE_SIDE_EFFECTS (memset_call) = 1;
1090+
1091+
ctx->add_statement (memset_call);
1092+
// BUILTIN size_of FN BODY END
1093+
1094+
finalize_intrinsic_block (ctx, fndecl);
1095+
1096+
return fndecl;
1097+
}
1098+
10451099
} // namespace Compile
10461100
} // namespace Rust

0 commit comments

Comments
 (0)