Merge commit 'e39eacd2d4
' into sync_cg_clif-2025-01-10
This commit is contained in:
commit
92a664e111
15 changed files with 93 additions and 320 deletions
|
@ -10,15 +10,15 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.94"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
|
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arbitrary"
|
name = "arbitrary"
|
||||||
version = "1.3.2"
|
version = "1.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
|
checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
|
@ -211,9 +211,9 @@ checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foldhash"
|
name = "foldhash"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
|
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gimli"
|
name = "gimli"
|
||||||
|
@ -253,15 +253,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.155"
|
version = "0.2.169"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.8.4"
|
version = "0.8.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
|
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets",
|
"windows-targets",
|
||||||
|
@ -290,9 +290,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "object"
|
name = "object"
|
||||||
version = "0.36.5"
|
version = "0.36.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e"
|
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"hashbrown 0.15.2",
|
"hashbrown 0.15.2",
|
||||||
|
@ -311,9 +311,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.36"
|
version = "1.0.38"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
@ -346,9 +346,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-hash"
|
name = "rustc-hash"
|
||||||
version = "2.0.0"
|
version = "2.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc_codegen_cranelift"
|
name = "rustc_codegen_cranelift"
|
||||||
|
@ -370,18 +370,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.215"
|
version = "1.0.217"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.215"
|
version = "1.0.217"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -402,9 +402,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.90"
|
version = "2.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
|
checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -419,9 +419,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.12"
|
version = "1.0.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasmtime-jit-icache-coherence"
|
name = "wasmtime-jit-icache-coherence"
|
||||||
|
|
|
@ -23,6 +23,14 @@ libloading = { version = "0.8.0", optional = true }
|
||||||
smallvec = "1.8.1"
|
smallvec = "1.8.1"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
# Uncomment to use an unreleased version of cranelift
|
||||||
|
#cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
|
||||||
|
#cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
|
||||||
|
#cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
|
||||||
|
#cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
|
||||||
|
#cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
|
||||||
|
#cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "release-28.0.0", version = "0.115.0" }
|
||||||
|
|
||||||
# Uncomment to use local checkout of cranelift
|
# Uncomment to use local checkout of cranelift
|
||||||
#cranelift-codegen = { path = "../wasmtime/cranelift/codegen" }
|
#cranelift-codegen = { path = "../wasmtime/cranelift/codegen" }
|
||||||
#cranelift-frontend = { path = "../wasmtime/cranelift/frontend" }
|
#cranelift-frontend = { path = "../wasmtime/cranelift/frontend" }
|
||||||
|
|
|
@ -33,14 +33,7 @@ pub(crate) fn build_sysroot(
|
||||||
let cg_clif_dylib_path = match cg_clif_dylib_src {
|
let cg_clif_dylib_path = match cg_clif_dylib_src {
|
||||||
CodegenBackend::Local(src_path) => {
|
CodegenBackend::Local(src_path) => {
|
||||||
// Copy the backend
|
// Copy the backend
|
||||||
let cg_clif_dylib_path = if cfg!(windows) {
|
let cg_clif_dylib_path = dist_dir.join("lib").join(src_path.file_name().unwrap());
|
||||||
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
|
|
||||||
// binaries.
|
|
||||||
dist_dir.join("bin")
|
|
||||||
} else {
|
|
||||||
dist_dir.join("lib")
|
|
||||||
}
|
|
||||||
.join(src_path.file_name().unwrap());
|
|
||||||
try_hard_link(src_path, &cg_clif_dylib_path);
|
try_hard_link(src_path, &cg_clif_dylib_path);
|
||||||
CodegenBackend::Local(cg_clif_dylib_path)
|
CodegenBackend::Local(cg_clif_dylib_path)
|
||||||
}
|
}
|
||||||
|
@ -102,19 +95,14 @@ pub(crate) fn build_sysroot(
|
||||||
.install_into_sysroot(dist_dir);
|
.install_into_sysroot(dist_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut target_compiler = {
|
let mut target_compiler = Compiler {
|
||||||
let rustc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustc-clif"));
|
cargo: bootstrap_host_compiler.cargo.clone(),
|
||||||
let rustdoc_clif = dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif"));
|
rustc: dist_dir.join(wrapper_base_name.replace("____", "rustc-clif")),
|
||||||
|
rustdoc: dist_dir.join(wrapper_base_name.replace("____", "rustdoc-clif")),
|
||||||
Compiler {
|
rustflags: vec![],
|
||||||
cargo: bootstrap_host_compiler.cargo.clone(),
|
rustdocflags: vec![],
|
||||||
rustc: rustc_clif.clone(),
|
triple: target_triple,
|
||||||
rustdoc: rustdoc_clif.clone(),
|
runner: vec![],
|
||||||
rustflags: vec![],
|
|
||||||
rustdocflags: vec![],
|
|
||||||
triple: target_triple,
|
|
||||||
runner: vec![],
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
if !is_native {
|
if !is_native {
|
||||||
target_compiler.set_cross_linker_and_runner();
|
target_compiler.set_cross_linker_and_runner();
|
||||||
|
|
|
@ -73,8 +73,6 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
|
||||||
"example/arbitrary_self_types_pointers_and_wrappers.rs",
|
"example/arbitrary_self_types_pointers_and_wrappers.rs",
|
||||||
&[],
|
&[],
|
||||||
),
|
),
|
||||||
TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
|
|
||||||
TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
|
|
||||||
TestCase::jit_bin("jit.std_example", "example/std_example.rs", "arg"),
|
TestCase::jit_bin("jit.std_example", "example/std_example.rs", "arg"),
|
||||||
TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
|
TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
|
||||||
TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
|
TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
|
||||||
|
@ -89,7 +87,6 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
|
||||||
&[],
|
&[],
|
||||||
),
|
),
|
||||||
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
|
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
|
||||||
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
|
|
||||||
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
|
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
|
||||||
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
|
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
|
||||||
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),
|
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),
|
||||||
|
|
|
@ -21,15 +21,12 @@ aot.mini_core_hello_world
|
||||||
testsuite.base_sysroot
|
testsuite.base_sysroot
|
||||||
aot.arbitrary_self_types_pointers_and_wrappers
|
aot.arbitrary_self_types_pointers_and_wrappers
|
||||||
aot.issue_91827_extern_types
|
aot.issue_91827_extern_types
|
||||||
build.alloc_system
|
|
||||||
aot.alloc_example
|
|
||||||
jit.std_example
|
jit.std_example
|
||||||
aot.std_example
|
aot.std_example
|
||||||
aot.dst_field_align
|
aot.dst_field_align
|
||||||
aot.subslice-patterns-const-eval
|
aot.subslice-patterns-const-eval
|
||||||
aot.track-caller-attribute
|
aot.track-caller-attribute
|
||||||
aot.float-minmax-pass
|
aot.float-minmax-pass
|
||||||
aot.mod_bench
|
|
||||||
aot.issue-72793
|
aot.issue-72793
|
||||||
aot.issue-59326
|
aot.issue-59326
|
||||||
aot.neon
|
aot.neon
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
|
|
||||||
#![allow(internal_features)]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
extern crate alloc;
|
|
||||||
extern crate alloc_system;
|
|
||||||
|
|
||||||
use alloc::boxed::Box;
|
|
||||||
|
|
||||||
use alloc_system::System;
|
|
||||||
|
|
||||||
#[global_allocator]
|
|
||||||
static ALLOC: System = System;
|
|
||||||
|
|
||||||
#[cfg_attr(unix, link(name = "c"))]
|
|
||||||
#[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
|
|
||||||
extern "C" {
|
|
||||||
fn puts(s: *const u8) -> i32;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
|
|
||||||
core::intrinsics::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[alloc_error_handler]
|
|
||||||
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
|
|
||||||
core::intrinsics::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[lang = "eh_personality"]
|
|
||||||
fn eh_personality() -> ! {
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[start]
|
|
||||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
|
||||||
let world: Box<&str> = Box::new("Hello World!\0");
|
|
||||||
unsafe {
|
|
||||||
puts(*world as *const str as *const u8);
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
|
|
@ -1,124 +0,0 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
||||||
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
|
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
pub struct System;
|
|
||||||
|
|
||||||
#[cfg(any(windows, unix, target_os = "redox"))]
|
|
||||||
mod realloc_fallback {
|
|
||||||
use core::alloc::{GlobalAlloc, Layout};
|
|
||||||
use core::{cmp, ptr};
|
|
||||||
impl super::System {
|
|
||||||
pub(crate) unsafe fn realloc_fallback(
|
|
||||||
&self,
|
|
||||||
ptr: *mut u8,
|
|
||||||
old_layout: Layout,
|
|
||||||
new_size: usize,
|
|
||||||
) -> *mut u8 {
|
|
||||||
// Docs for GlobalAlloc::realloc require this to be valid:
|
|
||||||
let new_layout = Layout::from_size_align_unchecked(new_size, old_layout.align());
|
|
||||||
let new_ptr = GlobalAlloc::alloc(self, new_layout);
|
|
||||||
if !new_ptr.is_null() {
|
|
||||||
let size = cmp::min(old_layout.size(), new_size);
|
|
||||||
ptr::copy_nonoverlapping(ptr, new_ptr, size);
|
|
||||||
GlobalAlloc::dealloc(self, ptr, old_layout);
|
|
||||||
}
|
|
||||||
new_ptr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(any(unix, target_os = "redox"))]
|
|
||||||
mod platform {
|
|
||||||
use core::alloc::{GlobalAlloc, Layout};
|
|
||||||
use core::ffi::c_void;
|
|
||||||
use core::ptr;
|
|
||||||
|
|
||||||
use System;
|
|
||||||
extern "C" {
|
|
||||||
fn posix_memalign(memptr: *mut *mut c_void, align: usize, size: usize) -> i32;
|
|
||||||
fn free(p: *mut c_void);
|
|
||||||
}
|
|
||||||
unsafe impl GlobalAlloc for System {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
||||||
aligned_malloc(&layout)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
|
||||||
let ptr = self.alloc(layout.clone());
|
|
||||||
if !ptr.is_null() {
|
|
||||||
ptr::write_bytes(ptr, 0, layout.size());
|
|
||||||
}
|
|
||||||
ptr
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
|
||||||
free(ptr as *mut c_void)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
|
||||||
self.realloc_fallback(ptr, layout, new_size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
|
|
||||||
let mut out = ptr::null_mut();
|
|
||||||
let ret = posix_memalign(&mut out, layout.align(), layout.size());
|
|
||||||
if ret != 0 { ptr::null_mut() } else { out as *mut u8 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(windows)]
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
mod platform {
|
|
||||||
use core::alloc::{GlobalAlloc, Layout};
|
|
||||||
|
|
||||||
use System;
|
|
||||||
type LPVOID = *mut u8;
|
|
||||||
type HANDLE = LPVOID;
|
|
||||||
type SIZE_T = usize;
|
|
||||||
type DWORD = u32;
|
|
||||||
type BOOL = i32;
|
|
||||||
extern "system" {
|
|
||||||
fn GetProcessHeap() -> HANDLE;
|
|
||||||
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
|
|
||||||
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
|
|
||||||
fn GetLastError() -> DWORD;
|
|
||||||
}
|
|
||||||
#[repr(C)]
|
|
||||||
struct Header(*mut u8);
|
|
||||||
const HEAP_ZERO_MEMORY: DWORD = 0x00000008;
|
|
||||||
unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header {
|
|
||||||
&mut *(ptr as *mut Header).sub(1)
|
|
||||||
}
|
|
||||||
unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
|
|
||||||
let aligned = ptr.add(align - (ptr as usize & (align - 1)));
|
|
||||||
*get_header(aligned) = Header(ptr);
|
|
||||||
aligned
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn allocate_with_flags(layout: Layout, flags: DWORD) -> *mut u8 {
|
|
||||||
let size = layout.size() + layout.align();
|
|
||||||
let ptr = HeapAlloc(GetProcessHeap(), flags, size);
|
|
||||||
(if ptr.is_null() { ptr } else { align_ptr(ptr, layout.align()) }) as *mut u8
|
|
||||||
}
|
|
||||||
unsafe impl GlobalAlloc for System {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
||||||
allocate_with_flags(layout, 0)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
|
||||||
allocate_with_flags(layout, HEAP_ZERO_MEMORY)
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
|
||||||
let header = get_header(ptr);
|
|
||||||
let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID);
|
|
||||||
debug_assert!(err != 0, "Failed to free heap memory: {}", GetLastError());
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
|
||||||
self.realloc_fallback(ptr, layout, new_size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
#![feature(start, core_intrinsics, lang_items)]
|
|
||||||
#![allow(internal_features)]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
#[cfg_attr(unix, link(name = "c"))]
|
|
||||||
#[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
|
|
||||||
extern "C" {}
|
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
|
|
||||||
core::intrinsics::abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[lang = "eh_personality"]
|
|
||||||
fn eh_personality() {}
|
|
||||||
|
|
||||||
// Required for rustc_codegen_llvm
|
|
||||||
#[no_mangle]
|
|
||||||
unsafe extern "C" fn _Unwind_Resume() {
|
|
||||||
core::intrinsics::unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[start]
|
|
||||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
|
||||||
for i in 2..10_000_000 {
|
|
||||||
black_box((i + 1) % i);
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(never)]
|
|
||||||
fn black_box(i: u32) {
|
|
||||||
if i != 1 {
|
|
||||||
core::intrinsics::abort();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2025-01-05"
|
channel = "nightly-2025-01-10"
|
||||||
components = ["rust-src", "rustc-dev", "llvm-tools"]
|
components = ["rust-src", "rustc-dev", "llvm-tools"]
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn main() {
|
||||||
if let Some(name) = option_env!("BUILTIN_BACKEND") {
|
if let Some(name) = option_env!("BUILTIN_BACKEND") {
|
||||||
rustflags.push(format!("-Zcodegen-backend={name}"));
|
rustflags.push(format!("-Zcodegen-backend={name}"));
|
||||||
} else {
|
} else {
|
||||||
let dylib = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
|
let dylib = sysroot.join("lib").join(
|
||||||
env::consts::DLL_PREFIX.to_string()
|
env::consts::DLL_PREFIX.to_string()
|
||||||
+ "rustc_codegen_cranelift"
|
+ "rustc_codegen_cranelift"
|
||||||
+ env::consts::DLL_SUFFIX,
|
+ env::consts::DLL_SUFFIX,
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
sysroot = sysroot.parent().unwrap();
|
sysroot = sysroot.parent().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
|
let cg_clif_dylib_path = sysroot.join("lib").join(
|
||||||
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
|
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
sysroot = sysroot.parent().unwrap();
|
sysroot = sysroot.parent().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
|
let cg_clif_dylib_path = sysroot.join("lib").join(
|
||||||
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
|
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,8 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn maybe_codegen_checked<'tcx>(
|
pub(crate) fn maybe_codegen_mul_checked<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||||
bin_op: BinOp,
|
|
||||||
lhs: CValue<'tcx>,
|
lhs: CValue<'tcx>,
|
||||||
rhs: CValue<'tcx>,
|
rhs: CValue<'tcx>,
|
||||||
) -> Option<CValue<'tcx>> {
|
) -> Option<CValue<'tcx>> {
|
||||||
|
@ -78,32 +77,19 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
|
||||||
|
|
||||||
let is_signed = type_sign(lhs.layout().ty);
|
let is_signed = type_sign(lhs.layout().ty);
|
||||||
|
|
||||||
match bin_op {
|
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
|
||||||
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => unreachable!(),
|
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
|
||||||
BinOp::Add | BinOp::Sub => None,
|
let param_types = vec![
|
||||||
BinOp::Mul => {
|
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
|
||||||
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
|
AbiParam::new(types::I128),
|
||||||
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
|
AbiParam::new(types::I128),
|
||||||
let param_types = vec![
|
];
|
||||||
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
|
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
|
||||||
AbiParam::new(types::I128),
|
fx.lib_call(
|
||||||
AbiParam::new(types::I128),
|
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
|
||||||
];
|
param_types,
|
||||||
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
|
vec![],
|
||||||
fx.lib_call(
|
&args,
|
||||||
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
|
);
|
||||||
param_types,
|
Some(out_place.to_cvalue(fx))
|
||||||
vec![],
|
|
||||||
&args,
|
|
||||||
);
|
|
||||||
Some(out_place.to_cvalue(fx))
|
|
||||||
}
|
|
||||||
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
|
|
||||||
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => unreachable!(),
|
|
||||||
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
|
||||||
BinOp::Div | BinOp::Rem => unreachable!(),
|
|
||||||
BinOp::Cmp => unreachable!(),
|
|
||||||
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => unreachable!(),
|
|
||||||
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,12 +73,14 @@ impl Drop for TimingGuard {
|
||||||
|
|
||||||
impl cranelift_codegen::timing::Profiler for MeasuremeProfiler {
|
impl cranelift_codegen::timing::Profiler for MeasuremeProfiler {
|
||||||
fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
|
fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
|
||||||
let mut timing_guard =
|
let mut timing_guard = Box::new(TimingGuard {
|
||||||
TimingGuard { profiler: std::mem::ManuallyDrop::new(self.0.clone()), inner: None };
|
profiler: std::mem::ManuallyDrop::new(self.0.clone()),
|
||||||
|
inner: None,
|
||||||
|
});
|
||||||
timing_guard.inner = Some(
|
timing_guard.inner = Some(
|
||||||
unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
|
unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
|
||||||
.generic_activity(pass.description()),
|
.generic_activity(pass.description()),
|
||||||
);
|
);
|
||||||
Box::new(timing_guard)
|
timing_guard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {
|
pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> IntCC {
|
||||||
use BinOp::*;
|
use BinOp::*;
|
||||||
use IntCC::*;
|
use IntCC::*;
|
||||||
Some(match bin_op {
|
match bin_op {
|
||||||
Eq => Equal,
|
Eq => Equal,
|
||||||
Lt => {
|
Lt => {
|
||||||
if signed {
|
if signed {
|
||||||
|
@ -36,8 +36,8 @@ pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> {
|
||||||
UnsignedGreaterThan
|
UnsignedGreaterThan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return None,
|
_ => unreachable!(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn codegen_three_way_compare<'tcx>(
|
fn codegen_three_way_compare<'tcx>(
|
||||||
|
@ -48,8 +48,8 @@ fn codegen_three_way_compare<'tcx>(
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
// This emits `(lhs > rhs) - (lhs < rhs)`, which is cranelift's preferred form per
|
// This emits `(lhs > rhs) - (lhs < rhs)`, which is cranelift's preferred form per
|
||||||
// <https://github.com/bytecodealliance/wasmtime/blob/8052bb9e3b792503b225f2a5b2ba3bc023bff462/cranelift/codegen/src/prelude_opt.isle#L41-L47>
|
// <https://github.com/bytecodealliance/wasmtime/blob/8052bb9e3b792503b225f2a5b2ba3bc023bff462/cranelift/codegen/src/prelude_opt.isle#L41-L47>
|
||||||
let gt_cc = crate::num::bin_op_to_intcc(BinOp::Gt, signed).unwrap();
|
let gt_cc = crate::num::bin_op_to_intcc(BinOp::Gt, signed);
|
||||||
let lt_cc = crate::num::bin_op_to_intcc(BinOp::Lt, signed).unwrap();
|
let lt_cc = crate::num::bin_op_to_intcc(BinOp::Lt, signed);
|
||||||
let gt = fx.bcx.ins().icmp(gt_cc, lhs, rhs);
|
let gt = fx.bcx.ins().icmp(gt_cc, lhs, rhs);
|
||||||
let lt = fx.bcx.ins().icmp(lt_cc, lhs, rhs);
|
let lt = fx.bcx.ins().icmp(lt_cc, lhs, rhs);
|
||||||
let val = fx.bcx.ins().isub(gt, lt);
|
let val = fx.bcx.ins().isub(gt, lt);
|
||||||
|
@ -63,11 +63,7 @@ fn codegen_compare_bin_op<'tcx>(
|
||||||
lhs: Value,
|
lhs: Value,
|
||||||
rhs: Value,
|
rhs: Value,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
if bin_op == BinOp::Cmp {
|
let intcc = crate::num::bin_op_to_intcc(bin_op, signed);
|
||||||
return codegen_three_way_compare(fx, signed, lhs, rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
|
|
||||||
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
|
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
|
||||||
CValue::by_val(val, fx.layout_of(fx.tcx.types.bool))
|
CValue::by_val(val, fx.layout_of(fx.tcx.types.bool))
|
||||||
}
|
}
|
||||||
|
@ -79,7 +75,7 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||||
in_rhs: CValue<'tcx>,
|
in_rhs: CValue<'tcx>,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
match bin_op {
|
match bin_op {
|
||||||
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt | BinOp::Cmp => {
|
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
|
||||||
match in_lhs.layout().ty.kind() {
|
match in_lhs.layout().ty.kind() {
|
||||||
ty::Bool | ty::Uint(_) | ty::Int(_) | ty::Char => {
|
ty::Bool | ty::Uint(_) | ty::Int(_) | ty::Char => {
|
||||||
let signed = type_sign(in_lhs.layout().ty);
|
let signed = type_sign(in_lhs.layout().ty);
|
||||||
|
@ -91,6 +87,16 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BinOp::Cmp => match in_lhs.layout().ty.kind() {
|
||||||
|
ty::Bool | ty::Uint(_) | ty::Int(_) | ty::Char => {
|
||||||
|
let signed = type_sign(in_lhs.layout().ty);
|
||||||
|
let lhs = in_lhs.load_scalar(fx);
|
||||||
|
let rhs = in_rhs.load_scalar(fx);
|
||||||
|
|
||||||
|
return codegen_three_way_compare(fx, signed, lhs, rhs);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,10 +206,6 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
|
||||||
let lhs = in_lhs.load_scalar(fx);
|
let lhs = in_lhs.load_scalar(fx);
|
||||||
let rhs = in_rhs.load_scalar(fx);
|
let rhs = in_rhs.load_scalar(fx);
|
||||||
|
|
||||||
if let Some(res) = crate::codegen_i128::maybe_codegen_checked(fx, bin_op, in_lhs, in_rhs) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
let signed = type_sign(in_lhs.layout().ty);
|
let signed = type_sign(in_lhs.layout().ty);
|
||||||
|
|
||||||
let (res, has_overflow) = match bin_op {
|
let (res, has_overflow) = match bin_op {
|
||||||
|
@ -236,6 +238,10 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
|
||||||
(val, has_overflow)
|
(val, has_overflow)
|
||||||
}
|
}
|
||||||
BinOp::Mul => {
|
BinOp::Mul => {
|
||||||
|
if let Some(res) = crate::codegen_i128::maybe_codegen_mul_checked(fx, in_lhs, in_rhs) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
let ty = fx.bcx.func.dfg.value_type(lhs);
|
let ty = fx.bcx.func.dfg.value_type(lhs);
|
||||||
match ty {
|
match ty {
|
||||||
types::I8 | types::I16 | types::I32 if !signed => {
|
types::I8 | types::I16 | types::I32 if !signed => {
|
||||||
|
@ -357,14 +363,12 @@ pub(crate) fn codegen_float_binop<'tcx>(
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret_val = fx.lib_call(
|
fx.lib_call(
|
||||||
name,
|
name,
|
||||||
vec![AbiParam::new(ty), AbiParam::new(ty)],
|
vec![AbiParam::new(ty), AbiParam::new(ty)],
|
||||||
vec![AbiParam::new(ty)],
|
vec![AbiParam::new(ty)],
|
||||||
&[lhs, rhs],
|
&[lhs, rhs],
|
||||||
)[0];
|
)[0]
|
||||||
|
|
||||||
return CValue::by_val(ret_val, in_lhs.layout());
|
|
||||||
}
|
}
|
||||||
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
|
BinOp::Eq | BinOp::Lt | BinOp::Le | BinOp::Ne | BinOp::Ge | BinOp::Gt => {
|
||||||
let fltcc = match bin_op {
|
let fltcc = match bin_op {
|
||||||
|
@ -431,13 +435,9 @@ pub(crate) fn codegen_ptr_binop<'tcx>(
|
||||||
BinOp::Lt | BinOp::Le | BinOp::Ge | BinOp::Gt => {
|
BinOp::Lt | BinOp::Le | BinOp::Ge | BinOp::Gt => {
|
||||||
let ptr_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_ptr, rhs_ptr);
|
let ptr_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_ptr, rhs_ptr);
|
||||||
|
|
||||||
let ptr_cmp =
|
let ptr_cmp = fx.bcx.ins().icmp(bin_op_to_intcc(bin_op, false), lhs_ptr, rhs_ptr);
|
||||||
fx.bcx.ins().icmp(bin_op_to_intcc(bin_op, false).unwrap(), lhs_ptr, rhs_ptr);
|
let extra_cmp =
|
||||||
let extra_cmp = fx.bcx.ins().icmp(
|
fx.bcx.ins().icmp(bin_op_to_intcc(bin_op, false), lhs_extra, rhs_extra);
|
||||||
bin_op_to_intcc(bin_op, false).unwrap(),
|
|
||||||
lhs_extra,
|
|
||||||
rhs_extra,
|
|
||||||
);
|
|
||||||
|
|
||||||
fx.bcx.ins().select(ptr_eq, extra_cmp, ptr_cmp)
|
fx.bcx.ins().select(ptr_eq, extra_cmp, ptr_cmp)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue