From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id CB0113857702; Tue, 16 Jan 2024 18:13:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB0113857702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428820; bh=cNEyBOebXWMAqiClWViSnvFlKuqtCACRAtg6CQA4T1w=; h=From:To:Subject:Date:From; b=MLQsyZIuNsTMNixWrIA9OFMIpU0mkCrGak5UZh99Db980YbobhBvuyRxcRCaiaSPd HQYm+lFQeOh852SiGC1fqfOVyitam4iKqPYrzZa9U1KUf16GxZigQ1X3r13DpizTeI SbUFG6avwloqz6T2Lp0AlcxQOnU72owiww7S8wXY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8015] gccrs: Add intrinsics::assume X-Act-Checkin: gcc X-Git-Author: Owen Avery X-Git-Refname: refs/heads/trunk X-Git-Oldrev: a05079fa6c7ef8a7d11f988164367f8a3588d0e9 X-Git-Newrev: b786f697dd3512db393c6517b1e7d1afe097aae1 Message-Id: <20240116181340.CB0113857702@sourceware.org> Date: Tue, 16 Jan 2024 18:13:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b786f697dd3512db393c6517b1e7d1afe097aae1 commit r14-8015-gb786f697dd3512db393c6517b1e7d1afe097aae1 Author: Owen Avery Date: Wed Sep 13 12:32:33 2023 -0400 gccrs: Add intrinsics::assume gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (get_identifier): Add declaration. (assume_handler): New. (generic_intrinsics): Add assume_handler entry. gcc/testsuite/ChangeLog: * rust/compile/assume.rs: New test. Signed-off-by: Owen Avery Diff: --- gcc/rust/backend/rust-compile-intrinsic.cc | 53 ++++++++++++++++++++++++++++++ gcc/testsuite/rust/compile/assume.rs | 13 ++++++++ 2 files changed, 66 insertions(+) diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index 420ed2dffe0..2433b989946 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -32,6 +32,11 @@ #include "print-tree.h" +// declaration taken from "stringpool.h" +// the get_identifier macro causes compilation issues +extern tree +get_identifier (const char *); + namespace Rust { namespace Compile { @@ -83,6 +88,8 @@ static tree uninit_handler (Context *ctx, TyTy::FnType *fntype); static tree move_val_init_handler (Context *ctx, TyTy::FnType *fntype); +static tree +assume_handler (Context *ctx, TyTy::FnType *fntype); enum class Prefetch { @@ -231,6 +238,7 @@ static const std::mapget_params ().size () == 1); + rust_assert (fntype->param_at (0).second->get_kind () + == TyTy::TypeKind::BOOL); + + tree lookup = NULL_TREE; + if (check_for_cached_intrinsic (ctx, fntype, &lookup)) + return lookup; + + auto fndecl = compile_intrinsic_function (ctx, fntype); + + // TODO: make sure these are necessary + TREE_READONLY (fndecl) = 0; + DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1; + DECL_ATTRIBUTES (fndecl) = tree_cons (get_identifier ("always_inline"), + NULL_TREE, DECL_ATTRIBUTES (fndecl)); + + std::vector param_vars; + compile_fn_params (ctx, fntype, fndecl, ¶m_vars); + + if (!Backend::function_set_parameters (fndecl, param_vars)) + return error_mark_node; + + enter_intrinsic_block (ctx, fndecl); + + // BUILTIN assume FN BODY BEGIN + + tree val = Backend::var_expression (param_vars[0], UNDEF_LOCATION); + + tree assume_expr = build_call_expr_internal_loc (UNDEF_LOCATION, IFN_ASSUME, + void_type_node, 1, val); + TREE_SIDE_EFFECTS (assume_expr) = 1; + + ctx->add_statement (assume_expr); + // BUILTIN size_of FN BODY END + + finalize_intrinsic_block (ctx, fndecl); + + return fndecl; +} + } // namespace Compile } // namespace Rust diff --git a/gcc/testsuite/rust/compile/assume.rs b/gcc/testsuite/rust/compile/assume.rs new file mode 100644 index 00000000000..4dc2fefa86a --- /dev/null +++ b/gcc/testsuite/rust/compile/assume.rs @@ -0,0 +1,13 @@ +mod intrinsics { + extern "rust-intrinsic" { + pub fn assume(value: bool); + } +} + +pub fn foo(v: i32) -> i32 { + unsafe { intrinsics::assume (v == 12); } + v +} + +pub fn main() { +}