Skip to content

Commit 75f8bdb

Browse files
committed
Merge commit '3270432f4b0583104c8b9b6f695bf97d6bbf3ac2' into sync_cg_clif-2024-05-13
2 parents abb9563 + 3270432 commit 75f8bdb

31 files changed

+481
-166
lines changed

compiler/rustc_codegen_cranelift/.github/workflows/abi-cafe.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ jobs:
5151
if: matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
5252
run: rustup set default-host x86_64-pc-windows-gnu
5353

54+
- name: Use x86_64 compiler on macOS
55+
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
56+
run: rustup set default-host x86_64-apple-darwin
57+
58+
- name: Select XCode version
59+
if: matrix.os == 'macos-latest'
60+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
61+
5462
- name: Prepare dependencies
5563
run: ./y.sh prepare
5664

compiler/rustc_codegen_cranelift/.github/workflows/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,20 @@ jobs:
9898
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
9999
run: rustup set default-host x86_64-pc-windows-gnu
100100

101+
- name: Use x86_64 compiler on macOS
102+
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
103+
run: rustup set default-host x86_64-apple-darwin
104+
101105
- name: Install toolchain and emulator
102106
if: matrix.apt_deps != null
103107
run: |
104108
sudo apt-get update
105109
sudo apt-get install -y ${{ matrix.apt_deps }}
106110
111+
- name: Select XCode version
112+
if: matrix.os == 'macos-latest'
113+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
114+
107115
- name: Prepare dependencies
108116
run: ./y.sh prepare
109117

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

241+
- name: Use x86_64 compiler on macOS
242+
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
243+
run: rustup set default-host x86_64-apple-darwin
244+
233245
- name: Install MinGW toolchain
234246
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
235247
run: |
236248
sudo apt-get update
237249
sudo apt-get install -y gcc-mingw-w64-x86-64
238250
251+
- name: Select XCode version
252+
if: matrix.os == 'macos-latest'
253+
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
254+
239255
- name: Prepare dependencies
240256
run: ./y.sh prepare
241257

compiler/rustc_codegen_cranelift/.github/workflows/rustc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/cache@v4
2121
with:
2222
path: build/cg_clif
23-
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
23+
key: ${{ runner.os }}-rustc-test-cargo-build-target-${{ hashFiles('rust-toolchain', 'Cargo.lock') }}
2424

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

4848
- name: Install ripgrep
4949
run: |

compiler/rustc_codegen_cranelift/.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
# Build artifacts during normal use
2-
/y.bin
3-
/y.bin.dSYM
4-
/y.exe
5-
/y.pdb
62
/download
73
/build
84
/dist

compiler/rustc_codegen_cranelift/build_system/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ path = "main.rs"
1111
unstable-features = [] # for rust-analyzer
1212

1313
# Do not add any dependencies
14+
15+
[profile.dev]
16+
debug = 1

compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,16 @@ fn build_clif_sysroot_for_triple(
267267
prefix.to_str().unwrap()
268268
));
269269
}
270+
rustflags.push("-Zunstable-options".to_owned());
271+
for (name, values) in EXTRA_CHECK_CFGS {
272+
rustflags.push(check_cfg_arg(name, *values));
273+
}
270274
compiler.rustflags.extend(rustflags);
271275
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
272276
if channel == "release" {
273277
build_cmd.arg("--release");
274278
}
275-
build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind");
279+
build_cmd.arg("--features").arg("backtrace panic-unwind");
276280
build_cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "true");
277281
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
278282
if compiler.triple.contains("apple") {
@@ -326,3 +330,34 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
326330

327331
Some(target_libs)
328332
}
333+
334+
// Copied from https://github.com/rust-lang/rust/blob/4fd98a4b1b100f5329c6efae18031791f64372d2/src/bootstrap/src/utils/helpers.rs#L569-L585
335+
/// Create a `--check-cfg` argument invocation for a given name
336+
/// and it's values.
337+
fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
338+
// Creating a string of the values by concatenating each value:
339+
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
340+
let next = match values {
341+
Some(values) => {
342+
let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();
343+
344+
tmp.insert_str(1, "values(");
345+
tmp.push(')');
346+
tmp
347+
}
348+
None => "".to_string(),
349+
};
350+
format!("--check-cfg=cfg({name}{next})")
351+
}
352+
353+
const EXTRA_CHECK_CFGS: &[(&str, Option<&[&str]>)] = &[
354+
("bootstrap", None),
355+
("stdarch_intel_sde", None),
356+
("no_fp_fmt_parse", None),
357+
("no_global_oom_handling", None),
358+
("no_rc", None),
359+
("no_sync", None),
360+
("netbsd10", None),
361+
("backtrace_in_libstd", None),
362+
("target_arch", Some(&["xtensa"])),
363+
];

compiler/rustc_codegen_cranelift/build_system/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ fn main() {
147147

148148
let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
149149
(Ok(_), Ok(_), Ok(_)) => None,
150-
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
151-
_ => {
152-
eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set");
150+
(_, Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
151+
vars => {
152+
eprintln!(
153+
"If RUSTC or RUSTDOC is set, both need to be set and in addition CARGO needs to be set: {vars:?}"
154+
);
153155
process::exit(1);
154156
}
155157
};

compiler/rustc_codegen_cranelift/build_system/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
7777
),
7878
TestCase::build_lib("build.alloc_system", "example/alloc_system.rs", "lib"),
7979
TestCase::build_bin_and_run("aot.alloc_example", "example/alloc_example.rs", &[]),
80-
TestCase::jit_bin("jit.std_example", "example/std_example.rs", ""),
80+
TestCase::jit_bin("jit.std_example", "example/std_example.rs", "arg"),
8181
TestCase::build_bin_and_run("aot.std_example", "example/std_example.rs", &["arg"]),
8282
TestCase::build_bin_and_run("aot.dst_field_align", "example/dst-field-align.rs", &[]),
8383
TestCase::build_bin_and_run(

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
never_type,
55
linkage,
66
extern_types,
7+
naked_functions,
78
thread_local,
89
repr_simd,
910
raw_ref_op
@@ -340,6 +341,7 @@ fn main() {
340341
))]
341342
unsafe {
342343
global_asm_test();
344+
naked_test();
343345
}
344346

345347
// Both statics have a reference that points to the same anonymous allocation.
@@ -395,6 +397,14 @@ global_asm! {
395397
"
396398
}
397399

400+
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64"))]
401+
#[naked]
402+
extern "C" fn naked_test() {
403+
unsafe {
404+
asm!("ret", options(noreturn));
405+
}
406+
}
407+
398408
#[repr(C)]
399409
enum c_void {
400410
_1,

compiler/rustc_codegen_cranelift/example/std_example.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ struct I64X2(i64, i64);
210210
#[allow(improper_ctypes_definitions)]
211211
extern "C" fn foo(_a: I64X2) {}
212212

213+
#[cfg(target_arch = "x86_64")]
214+
#[target_feature(enable = "sse4.2")]
215+
#[cfg(not(jit))]
216+
unsafe fn test_crc32() {
217+
assert!(is_x86_feature_detected!("sse4.2"));
218+
219+
let a = 42u32;
220+
let b = 0xdeadbeefu64;
221+
222+
assert_eq!(_mm_crc32_u8(a, b as u8), 4135334616);
223+
assert_eq!(_mm_crc32_u16(a, b as u16), 1200687288);
224+
assert_eq!(_mm_crc32_u32(a, b as u32), 2543798776);
225+
assert_eq!(_mm_crc32_u64(a as u64, b as u64), 241952147);
226+
}
227+
213228
#[cfg(target_arch = "x86_64")]
214229
#[target_feature(enable = "sse2")]
215230
unsafe fn test_simd() {
@@ -244,10 +259,14 @@ unsafe fn test_simd() {
244259

245260
test_mm256_shuffle_epi8();
246261
test_mm256_permute2x128_si256();
262+
test_mm256_permutevar8x32_epi32();
247263

248264
#[rustfmt::skip]
249265
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)));
250266
assert_eq!(mask1, 1);
267+
268+
#[cfg(not(jit))]
269+
test_crc32();
251270
}
252271

253272
#[cfg(target_arch = "x86_64")]
@@ -447,6 +466,16 @@ unsafe fn test_mm256_permute2x128_si256() {
447466
assert_eq_m256i(r, e);
448467
}
449468

469+
#[cfg(target_arch = "x86_64")]
470+
#[target_feature(enable = "avx2")]
471+
unsafe fn test_mm256_permutevar8x32_epi32() {
472+
let a = _mm256_setr_epi32(100, 200, 300, 400, 500, 600, 700, 800);
473+
let idx = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0);
474+
let r = _mm256_setr_epi32(800, 700, 600, 500, 400, 300, 200, 100);
475+
let e = _mm256_permutevar8x32_epi32(a, idx);
476+
assert_eq_m256i(r, e);
477+
}
478+
450479
fn test_checked_mul() {
451480
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
452481
assert_eq!(u, None);

0 commit comments

Comments
 (0)