Skip to content

Subtree sync for rustc_codegen_cranelift #125074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d5273ff
Do intrinsic changes in `rustc_codegen_cranelift`
WaffleLapkin Apr 19, 2024
4ad6c6c
Merge commit 'de5d6523738fd44a0521b6abf3e73ae1df210741' into sync_cg_…
bjorn3 Apr 23, 2024
f7627c3
Fix broken subtree sync
bjorn3 Apr 23, 2024
1122338
Merge branch 'sync_from_rust'
bjorn3 Apr 23, 2024
6a2ad55
Rollup merge of #124003 - WaffleLapkin:dellvmization, r=scottmcm,Ralf…
matthiaskrgr Apr 23, 2024
36449f8
Rollup merge of #124286 - bjorn3:sync_cg_clif-2024-04-23, r=bjorn3
matthiaskrgr Apr 23, 2024
dda4709
Error on using `yield` without also using `#[coroutine]` on the closure
oli-obk Apr 11, 2024
9a57c63
debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo`…
petrochenkov Feb 9, 2024
18a109e
Sync from rust aed2187d53b8789e3a37f50ae36f894a2a679077
bjorn3 Apr 28, 2024
a07fd93
Rustup to rustc 1.79.0-nightly (aed2187d5 2024-04-27)
bjorn3 Apr 28, 2024
1e485f1
Fix rustc tests
bjorn3 Apr 28, 2024
05367c5
Downgrade XCode to workaround a bug in ld prime
bjorn3 Apr 28, 2024
18d2fb6
Rustup to rustc 1.80.0-nightly (79734f1db 2024-05-02)
bjorn3 May 3, 2024
c41a7db
Fix rustc test suite
bjorn3 May 3, 2024
88d1068
Remove special case in maybe_create_entry_wrapper
bjorn3 May 3, 2024
b1ebc55
Correctly handle missing CG_CLIF_JIT_ARGS
bjorn3 May 3, 2024
4d6ac05
Add missing arg for the jit.std_example test
bjorn3 May 3, 2024
617c3f6
Refactor float `Primitive`s to a separate `Float` type
beetrees May 6, 2024
0a67bf1
Make builtin_deref just return a Ty
compiler-errors May 10, 2024
80e2a78
Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoe…
matthiaskrgr May 10, 2024
6633d66
Sync from rust 6e1d94708a0a4a35ca7e46c6cac98adf62fe800e
bjorn3 May 11, 2024
250d083
Rustup to rustc 1.80.0-nightly (6e1d94708 2024-05-10)
bjorn3 May 11, 2024
8fe6e74
Fix rustc tests
bjorn3 May 11, 2024
f437815
Compile for x86_64 on macOS even with an arm64 host
bjorn3 May 11, 2024
8cf40c4
Don't attempt to polymorphize statics
bjorn3 May 11, 2024
906db02
Avoid CValue::const_val for discriminants
bjorn3 May 11, 2024
9e4e805
Avoid ICE on transmuting invalid bools
bjorn3 May 11, 2024
9ee010c
Try to workaround gha issue with the caching action
bjorn3 May 11, 2024
50b3427
Split cgus into todo and done before the main module codegen loop
bjorn3 May 11, 2024
a167142
Translate MIR to clif ir in parallel with parallel rustc
bjorn3 May 11, 2024
7b50189
add the `llvm.x86.sse42.crc32.32.32` intrinsic (#1488)
folkertdev May 11, 2024
e7b6662
support crc32 with 8-bit and 16-bit inputs, and add crc64 support
folkertdev May 11, 2024
4a4535a
add `llvm.x86.avx2.permd` intrinsic
folkertdev May 11, 2024
893ba53
Merge pull request #1491 from folkertdev/add-llvm-avx2-permd
bjorn3 May 11, 2024
1a2c489
Merge pull request #1489 from rust-lang/parallel_rustc
bjorn3 May 11, 2024
9059a74
test x86 crc intrinsics
folkertdev May 11, 2024
2df34f9
Merge pull request #1490 from folkertdev/add-llvm-x86-crc32
bjorn3 May 11, 2024
cfc919f
Use cargo in y.sh
bjorn3 May 12, 2024
6db2752
Significantly reduce check cfg warnings
bjorn3 May 12, 2024
0627c63
Remove polymorphize calls for statics in a couple more places
bjorn3 May 12, 2024
cba05a7
Support naked functions
bjorn3 May 12, 2024
df88c11
Use the target cpu from the target spec on x86_64 when -Ctarget-cpu i…
bjorn3 May 12, 2024
3270432
Rustup to rustc 1.80.0-nightly (ef0027897 2024-05-12)
bjorn3 May 13, 2024
75f8bdb
Merge commit '3270432f4b0583104c8b9b6f695bf97d6bbf3ac2' into sync_cg_…
bjorn3 May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ jobs:
if: matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: rustup set default-host x86_64-pc-windows-gnu

- name: Use x86_64 compiler on macOS
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
run: rustup set default-host x86_64-apple-darwin

- name: Select XCode version
if: matrix.os == 'macos-latest'
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app

- name: Prepare dependencies
run: ./y.sh prepare

Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ jobs:
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: rustup set default-host x86_64-pc-windows-gnu

- name: Use x86_64 compiler on macOS
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
run: rustup set default-host x86_64-apple-darwin

- name: Install toolchain and emulator
if: matrix.apt_deps != null
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.apt_deps }}

- name: Select XCode version
if: matrix.os == 'macos-latest'
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app

- name: Prepare dependencies
run: ./y.sh prepare

Expand Down Expand Up @@ -230,12 +238,20 @@ jobs:
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: rustup set default-host x86_64-pc-windows-gnu

- name: Use x86_64 compiler on macOS
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
run: rustup set default-host x86_64-apple-darwin

- name: Install MinGW toolchain
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64

- name: Select XCode version
if: matrix.os == 'macos-latest'
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app

- name: Prepare dependencies
run: ./y.sh prepare

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/.github/workflows/rustc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
key: ${{ runner.os }}-rustc-test-cargo-build-target-${{ hashFiles('rust-toolchain', 'Cargo.lock') }}

- name: Prepare dependencies
run: ./y.sh prepare
Expand All @@ -43,7 +43,7 @@ jobs:
uses: actions/cache@v4
with:
path: build/cg_clif
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
key: ${{ runner.os }}-rustc-test-cargo-build-target-${{ hashFiles('rust-toolchain', 'Cargo.lock') }}

- name: Install ripgrep
run: |
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_cranelift/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Build artifacts during normal use
/y.bin
/y.bin.dSYM
/y.exe
/y.pdb
/download
/build
/dist
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_cranelift/build_system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ path = "main.rs"
unstable-features = [] # for rust-analyzer

# Do not add any dependencies

[profile.dev]
debug = 1
37 changes: 36 additions & 1 deletion compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,16 @@ fn build_clif_sysroot_for_triple(
prefix.to_str().unwrap()
));
}
rustflags.push("-Zunstable-options".to_owned());
for (name, values) in EXTRA_CHECK_CFGS {
rustflags.push(check_cfg_arg(name, *values));
}
compiler.rustflags.extend(rustflags);
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
if channel == "release" {
build_cmd.arg("--release");
}
build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind");
build_cmd.arg("--features").arg("backtrace panic-unwind");
build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
if compiler.triple.contains("apple") {
Expand Down Expand Up @@ -326,3 +330,34 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {

Some(target_libs)
}

// Copied from https://github.com/rust-lang/rust/blob/4fd98a4b1b100f5329c6efae18031791f64372d2/src/bootstrap/src/utils/helpers.rs#L569-L585
/// Create a `--check-cfg` argument invocation for a given name
/// and it's values.
fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
// Creating a string of the values by concatenating each value:
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
let next = match values {
Some(values) => {
let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();

tmp.insert_str(1, "values(");
tmp.push(')');
tmp
}
None => "".to_string(),
};
format!("--check-cfg=cfg({name}{next})")
}

const EXTRA_CHECK_CFGS: &[(&str, Option<&[&str]>)] = &[
("bootstrap", None),
("stdarch_intel_sde", None),
("no_fp_fmt_parse", None),
("no_global_oom_handling", None),
("no_rc", None),
("no_sync", None),
("netbsd10", None),
("backtrace_in_libstd", None),
("target_arch", Some(&["xtensa"])),
];
8 changes: 5 additions & 3 deletions compiler/rustc_codegen_cranelift/build_system/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ fn main() {

let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
(Ok(_), Ok(_), Ok(_)) => None,
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
_ => {
eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set");
(_, Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
vars => {
eprintln!(
"If RUSTC or RUSTDOC is set, both need to be set and in addition CARGO needs to be set: {vars:?}"
);
process::exit(1);
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/build_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
),
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", ""),
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.dst_field_align", "example/dst-field-align.rs", &[]),
TestCase::build_bin_and_run(
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
never_type,
linkage,
extern_types,
naked_functions,
thread_local,
repr_simd,
raw_ref_op
Expand Down Expand Up @@ -340,6 +341,7 @@ fn main() {
))]
unsafe {
global_asm_test();
naked_test();
}

// Both statics have a reference that points to the same anonymous allocation.
Expand Down Expand Up @@ -395,6 +397,14 @@ global_asm! {
"
}

#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64"))]
#[naked]
extern "C" fn naked_test() {
unsafe {
asm!("ret", options(noreturn));
}
}

#[repr(C)]
enum c_void {
_1,
Expand Down
29 changes: 29 additions & 0 deletions compiler/rustc_codegen_cranelift/example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ struct I64X2(i64, i64);
#[allow(improper_ctypes_definitions)]
extern "C" fn foo(_a: I64X2) {}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse4.2")]
#[cfg(not(jit))]
unsafe fn test_crc32() {
assert!(is_x86_feature_detected!("sse4.2"));

let a = 42u32;
let b = 0xdeadbeefu64;

assert_eq!(_mm_crc32_u8(a, b as u8), 4135334616);
assert_eq!(_mm_crc32_u16(a, b as u16), 1200687288);
assert_eq!(_mm_crc32_u32(a, b as u32), 2543798776);
assert_eq!(_mm_crc32_u64(a as u64, b as u64), 241952147);
}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
unsafe fn test_simd() {
Expand Down Expand Up @@ -244,10 +259,14 @@ unsafe fn test_simd() {

test_mm256_shuffle_epi8();
test_mm256_permute2x128_si256();
test_mm256_permutevar8x32_epi32();

#[rustfmt::skip]
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
assert_eq!(mask1, 1);

#[cfg(not(jit))]
test_crc32();
}

#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -447,6 +466,16 @@ unsafe fn test_mm256_permute2x128_si256() {
assert_eq_m256i(r, e);
}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
unsafe fn test_mm256_permutevar8x32_epi32() {
let a = _mm256_setr_epi32(100, 200, 300, 400, 500, 600, 700, 800);
let idx = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0);
let r = _mm256_setr_epi32(800, 700, 600, 500, 400, 300, 200, 100);
let e = _mm256_permutevar8x32_epi32(a, idx);
assert_eq_m256i(r, e);
}

fn test_checked_mul() {
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
assert_eq!(u, None);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"

[[package]]
name = "cc"
version = "1.0.90"
version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4"

[[package]]
name = "cfg-if"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-04-23"
channel = "nightly-2024-05-13"
components = ["rust-src", "rustc-dev", "llvm-tools"]
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ rm tests/incremental/hashes/statics.rs # same
rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs
rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support
rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support
rm tests/ui/delegation/fn-header.rs

# unsized locals
rm -r tests/run-pass-valgrind/unsized-locals
Expand Down Expand Up @@ -87,6 +88,7 @@ rm -r tests/run-make/no-builtins-attribute # same
rm tests/ui/abi/stack-protector.rs # requires stack protector support
rm -r tests/run-make/emit-stack-sizes # requires support for -Z emit-stack-sizes
rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific
rm -r tests/run-make/print-to-output # requires --print relocation-models

# requires asm, llvm-ir and/or llvm-bc emit support
# =============================================
Expand Down Expand Up @@ -151,7 +153,7 @@ index 9607ff02f96..b7d97caf9a2 100644
let mut cmd = setup_common();
- let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
Self { cmd }
Self { cmd, stdin: None }
}

EOF
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
Err(instance) => Some(instance),
}
}
InstanceDef::DropGlue(_, None) => {
InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) => {
// empty drop glue - a nop.
let dest = target.expect("Non terminating drop_in_place_real???");
let ret_block = fx.get_block(dest);
Expand Down Expand Up @@ -597,7 +597,9 @@ pub(crate) fn codegen_drop<'tcx>(
let ty = drop_place.layout().ty;
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);

if let ty::InstanceDef::DropGlue(_, None) = drop_instance.def {
if let ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) =
drop_instance.def
{
// we don't actually need to drop anything
} else {
match ty.kind() {
Expand Down
37 changes: 35 additions & 2 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_module::ModuleError;
use rustc_ast::InlineAsmOptions;
use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
Expand All @@ -14,6 +15,7 @@ use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphizat

use crate::constant::ConstantCx;
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
use crate::inline_asm::codegen_naked_asm;
use crate::prelude::*;
use crate::pretty_clif::CommentWriter;

Expand All @@ -32,7 +34,7 @@ pub(crate) fn codegen_fn<'tcx>(
cached_func: Function,
module: &mut dyn Module,
instance: Instance<'tcx>,
) -> CodegenedFunction {
) -> Option<CodegenedFunction> {
debug_assert!(!instance.args.has_infer());

let symbol_name = tcx.symbol_name(instance).name.to_string();
Expand All @@ -48,6 +50,37 @@ pub(crate) fn codegen_fn<'tcx>(
String::from_utf8_lossy(&buf).into_owned()
});

if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
assert_eq!(mir.basic_blocks.len(), 1);
assert!(mir.basic_blocks[START_BLOCK].statements.is_empty());

match &mir.basic_blocks[START_BLOCK].terminator().kind {
TerminatorKind::InlineAsm {
template,
operands,
options,
line_spans: _,
targets: _,
unwind: _,
} => {
codegen_naked_asm(
tcx,
cx,
module,
instance,
mir.basic_blocks[START_BLOCK].terminator().source_info.span,
&symbol_name,
template,
operands,
*options,
);
}
_ => unreachable!(),
}

return None;
}

// Declare function
let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance);
let func_id = module.declare_function(&symbol_name, Linkage::Local, &sig).unwrap();
Expand Down Expand Up @@ -128,7 +161,7 @@ pub(crate) fn codegen_fn<'tcx>(
// Verify function
verify_func(tcx, &clif_comments, &func);

CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
}

pub(crate) fn compile_fn(
Expand Down
Loading
Loading