From e8e6663167618b7674165f894edf7acbf03980e1 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 18 Jun 2024 12:56:20 -0400 Subject: [PATCH] Fix provenance intrinsics --- Cargo.lock | 6 +- Cargo.toml | 3 +- rust-toolchain | 2 +- src/intrinsic/simd.rs | 135 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ecb0ef6b4d..ba6633bc2dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,8 +80,7 @@ dependencies = [ [[package]] name = "gccjit" version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecaa4c3da2d74c1a991b4faff75d49ab1d0522d9a99d8e2614b3b04d226417ce" +source = "git+https://github.com/rust-lang/gccjit.rs#f1545d7c2c13e42d78eaac8032d49ab8f7d43b6e" dependencies = [ "gccjit_sys", ] @@ -89,8 +88,7 @@ dependencies = [ [[package]] name = "gccjit_sys" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406a66fba005f1a02661f2f9443e5693dd3a667b7c58e70aa4ccc4c8b50b4758" +source = "git+https://github.com/rust-lang/gccjit.rs#f1545d7c2c13e42d78eaac8032d49ab8f7d43b6e" dependencies = [ "libc", ] diff --git a/Cargo.toml b/Cargo.toml index c5aa2eed1e0..309746f04e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,8 @@ master = ["gccjit/master"] default = ["master"] [dependencies] -gccjit = "2.0" +#gccjit = "2.0" +gccjit = { git = "https://github.com/rust-lang/gccjit.rs" } # Local copy. #gccjit = { path = "../gccjit.rs" } diff --git a/rust-toolchain b/rust-toolchain index a0ac8286660..7a1806fe3c7 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2024-03-05" +channel = "nightly-2024-06-18" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs index 9dfdff1fdcb..0c52bfd2192 100644 --- a/src/intrinsic/simd.rs +++ b/src/intrinsic/simd.rs @@ -436,6 +436,141 @@ macro_rules! require_simd { return Ok(bx.vector_select(args[0].immediate(), args[1].immediate(), args[2].immediate())); } + if name == sym::simd_cast_ptr { + require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); + let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); + + require!( + in_len == out_len, + InvalidMonomorphization::ReturnLengthInputType { + span, + name, + in_len, + in_ty, + ret_ty, + out_len + } + ); + + match *in_elem.kind() { + ty::RawPtr(p_ty, _) => { + let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { + bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty) + }); + require!( + metadata.is_unit(), + InvalidMonomorphization::CastFatPointer { span, name, ty: in_elem } + ); + } + _ => { + return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem }) + } + } + match *out_elem.kind() { + ty::RawPtr(p_ty, _) => { + let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { + bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty) + }); + require!( + metadata.is_unit(), + InvalidMonomorphization::CastFatPointer { span, name, ty: out_elem } + ); + } + _ => { + return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem }) + } + } + + let arg = args[0].immediate(); + let elem_type = llret_ty.dyncast_vector().expect("vector return type").get_element_type(); + let values: Vec<_> = (0..in_len) + .map(|i| { + let idx = bx.gcc_int(bx.usize_type, i as _); + let value = bx.extract_element(arg, idx); + bx.pointercast(value, elem_type) + }) + .collect(); + return Ok(bx.context.new_rvalue_from_vector(bx.location, llret_ty, &values)); + } + + if name == sym::simd_expose_provenance { + require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); + let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); + + require!( + in_len == out_len, + InvalidMonomorphization::ReturnLengthInputType { + span, + name, + in_len, + in_ty, + ret_ty, + out_len + } + ); + + match *in_elem.kind() { + ty::RawPtr(_, _) => {} + _ => { + return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem }) + } + } + match *out_elem.kind() { + ty::Uint(ty::UintTy::Usize) => {} + _ => return_error!(InvalidMonomorphization::ExpectedUsize { span, name, ty: out_elem }), + } + + let arg = args[0].immediate(); + let elem_type = llret_ty.dyncast_vector().expect("vector return type").get_element_type(); + let values: Vec<_> = (0..in_len) + .map(|i| { + let idx = bx.gcc_int(bx.usize_type, i as _); + let value = bx.extract_element(arg, idx); + bx.ptrtoint(value, elem_type) + }) + .collect(); + return Ok(bx.context.new_rvalue_from_vector(bx.location, llret_ty, &values)); + } + + if name == sym::simd_with_exposed_provenance { + require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty }); + let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx()); + + require!( + in_len == out_len, + InvalidMonomorphization::ReturnLengthInputType { + span, + name, + in_len, + in_ty, + ret_ty, + out_len + } + ); + + match *in_elem.kind() { + ty::Uint(ty::UintTy::Usize) => {} + _ => return_error!(InvalidMonomorphization::ExpectedUsize { span, name, ty: in_elem }), + } + match *out_elem.kind() { + ty::RawPtr(_, _) => {} + _ => { + return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem }) + } + } + + let arg = args[0].immediate(); + let elem_type = llret_ty.dyncast_vector().expect("vector return type").get_element_type(); + let values: Vec<_> = (0..in_len) + .map(|i| { + let idx = bx.gcc_int(bx.usize_type, i as _); + let value = bx.extract_element(arg, idx); + bx.inttoptr(value, elem_type) + }) + .collect(); + return Ok(bx.context.new_rvalue_from_vector(bx.location, llret_ty, &values)); + } + #[cfg(feature = "master")] if name == sym::simd_cast || name == sym::simd_as { require_simd!(ret_ty, InvalidMonomorphization::SimdReturn { span, name, ty: ret_ty });