Skip to content

Commit 75f8bdb

Browse files
committedMay 13, 2024
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

+8
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

+16
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

+2-2
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

-4
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

+3
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

+36-1
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

+5-3
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

+1-1
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

+10
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

+29
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);

‎compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
4242

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

4949
[[package]]
5050
name = "cfg-if"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-04-23"
2+
channel = "nightly-2024-05-13"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

‎compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ rm tests/incremental/hashes/statics.rs # same
4444
rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs
4545
rm tests/ui/abi/variadic-ffi.rs # requires callee side vararg support
4646
rm -r tests/run-make/c-link-to-rust-va-list-fn # requires callee side vararg support
47+
rm tests/ui/delegation/fn-header.rs
4748

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

9193
# requires asm, llvm-ir and/or llvm-bc emit support
9294
# =============================================
@@ -151,7 +153,7 @@ index 9607ff02f96..b7d97caf9a2 100644
151153
let mut cmd = setup_common();
152154
- let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
153155
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
154-
Self { cmd }
156+
Self { cmd, stdin: None }
155157
}
156158
157159
EOF

‎compiler/rustc_codegen_cranelift/src/abi/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
412412
Err(instance) => Some(instance),
413413
}
414414
}
415-
InstanceDef::DropGlue(_, None) => {
415+
InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) => {
416416
// empty drop glue - a nop.
417417
let dest = target.expect("Non terminating drop_in_place_real???");
418418
let ret_block = fx.get_block(dest);
@@ -597,7 +597,9 @@ pub(crate) fn codegen_drop<'tcx>(
597597
let ty = drop_place.layout().ty;
598598
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
599599

600-
if let ty::InstanceDef::DropGlue(_, None) = drop_instance.def {
600+
if let ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) =
601+
drop_instance.def
602+
{
601603
// we don't actually need to drop anything
602604
} else {
603605
match ty.kind() {

‎compiler/rustc_codegen_cranelift/src/base.rs

+35-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
66
use cranelift_module::ModuleError;
77
use rustc_ast::InlineAsmOptions;
88
use rustc_index::IndexVec;
9+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
910
use rustc_middle::ty::adjustment::PointerCoercion;
1011
use rustc_middle::ty::layout::FnAbiOf;
1112
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -14,6 +15,7 @@ use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphizat
1415

1516
use crate::constant::ConstantCx;
1617
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
18+
use crate::inline_asm::codegen_naked_asm;
1719
use crate::prelude::*;
1820
use crate::pretty_clif::CommentWriter;
1921

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

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

53+
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
54+
assert_eq!(mir.basic_blocks.len(), 1);
55+
assert!(mir.basic_blocks[START_BLOCK].statements.is_empty());
56+
57+
match &mir.basic_blocks[START_BLOCK].terminator().kind {
58+
TerminatorKind::InlineAsm {
59+
template,
60+
operands,
61+
options,
62+
line_spans: _,
63+
targets: _,
64+
unwind: _,
65+
} => {
66+
codegen_naked_asm(
67+
tcx,
68+
cx,
69+
module,
70+
instance,
71+
mir.basic_blocks[START_BLOCK].terminator().source_info.span,
72+
&symbol_name,
73+
template,
74+
operands,
75+
*options,
76+
);
77+
}
78+
_ => unreachable!(),
79+
}
80+
81+
return None;
82+
}
83+
5184
// Declare function
5285
let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance);
5386
let func_id = module.declare_function(&symbol_name, Linkage::Local, &sig).unwrap();
@@ -128,7 +161,7 @@ pub(crate) fn codegen_fn<'tcx>(
128161
// Verify function
129162
verify_func(tcx, &clif_comments, &func);
130163

131-
CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
164+
Some(CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx })
132165
}
133166

134167
pub(crate) fn compile_fn(

‎compiler/rustc_codegen_cranelift/src/concurrency_limiter.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_session::Session;
66
// FIXME don't panic when a worker thread panics
77

88
pub(super) struct ConcurrencyLimiter {
9-
helper_thread: Option<HelperThread>,
9+
helper_thread: Option<Mutex<HelperThread>>,
1010
state: Arc<Mutex<state::ConcurrencyLimiterState>>,
1111
available_token_condvar: Arc<Condvar>,
1212
finished: bool,
@@ -39,14 +39,14 @@ impl ConcurrencyLimiter {
3939
})
4040
.unwrap();
4141
ConcurrencyLimiter {
42-
helper_thread: Some(helper_thread),
42+
helper_thread: Some(Mutex::new(helper_thread)),
4343
state,
4444
available_token_condvar,
4545
finished: false,
4646
}
4747
}
4848

49-
pub(super) fn acquire(&mut self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
49+
pub(super) fn acquire(&self, dcx: &rustc_errors::DiagCtxt) -> ConcurrencyLimiterToken {
5050
let mut state = self.state.lock().unwrap();
5151
loop {
5252
state.assert_invariants();
@@ -73,16 +73,11 @@ impl ConcurrencyLimiter {
7373
}
7474
}
7575

76-
self.helper_thread.as_mut().unwrap().request_token();
76+
self.helper_thread.as_ref().unwrap().lock().unwrap().request_token();
7777
state = self.available_token_condvar.wait(state).unwrap();
7878
}
7979
}
8080

81-
pub(super) fn job_already_done(&mut self) {
82-
let mut state = self.state.lock().unwrap();
83-
state.job_already_done();
84-
}
85-
8681
pub(crate) fn finished(mut self) {
8782
self.helper_thread.take();
8883

@@ -190,14 +185,6 @@ mod state {
190185
self.assert_invariants();
191186
}
192187

193-
pub(super) fn job_already_done(&mut self) {
194-
self.assert_invariants();
195-
self.pending_jobs -= 1;
196-
self.assert_invariants();
197-
self.drop_excess_capacity();
198-
self.assert_invariants();
199-
}
200-
201188
pub(super) fn poison(&mut self, error: String) {
202189
self.poisoned = true;
203190
self.stored_error = Some(error);

‎compiler/rustc_codegen_cranelift/src/config.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ impl Default for BackendConfig {
6464
BackendConfig {
6565
codegen_mode: CodegenMode::Aot,
6666
jit_args: {
67-
let args = std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new());
68-
args.split(' ').map(|arg| arg.to_string()).collect()
67+
match std::env::var("CG_CLIF_JIT_ARGS") {
68+
Ok(args) => args.split(' ').map(|arg| arg.to_string()).collect(),
69+
Err(std::env::VarError::NotPresent) => vec![],
70+
Err(std::env::VarError::NotUnicode(s)) => {
71+
panic!("CG_CLIF_JIT_ARGS not unicode: {:?}", s);
72+
}
73+
}
6974
},
7075
enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"),
7176
disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"),

‎compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn data_id_for_static(
258258
) -> DataId {
259259
let attrs = tcx.codegen_fn_attrs(def_id);
260260

261-
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
261+
let instance = Instance::mono(tcx, def_id);
262262
let symbol_name = tcx.symbol_name(instance).name;
263263

264264
if let Some(import_linkage) = attrs.import_linkage {

‎compiler/rustc_codegen_cranelift/src/discriminant.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
2828
} => {
2929
let ptr = place.place_field(fx, FieldIdx::new(tag_field));
3030
let to = layout.ty.discriminant_for_variant(fx.tcx, variant_index).unwrap().val;
31-
let to = if ptr.layout().abi.is_signed() {
32-
ty::ScalarInt::try_from_int(
33-
ptr.layout().size.sign_extend(to) as i128,
34-
ptr.layout().size,
35-
)
36-
.unwrap()
37-
} else {
38-
ty::ScalarInt::try_from_uint(to, ptr.layout().size).unwrap()
31+
let to = match ptr.layout().ty.kind() {
32+
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
33+
let lsb = fx.bcx.ins().iconst(types::I64, to as u64 as i64);
34+
let msb = fx.bcx.ins().iconst(types::I64, (to >> 64) as u64 as i64);
35+
fx.bcx.ins().iconcat(lsb, msb)
36+
}
37+
ty::Uint(_) | ty::Int(_) => {
38+
let clif_ty = fx.clif_type(ptr.layout().ty).unwrap();
39+
let raw_val = ptr.layout().size.truncate(to);
40+
fx.bcx.ins().iconst(clif_ty, raw_val as i64)
41+
}
42+
_ => unreachable!(),
3943
};
40-
let discr = CValue::const_val(fx, ptr.layout(), to);
44+
let discr = CValue::by_val(to, ptr.layout());
4145
ptr.write_cvalue(fx, discr);
4246
}
4347
Variants::Multiple {
@@ -85,16 +89,21 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
8589
.ty
8690
.discriminant_for_variant(fx.tcx, *index)
8791
.map_or(u128::from(index.as_u32()), |discr| discr.val);
88-
let discr_val = if dest_layout.abi.is_signed() {
89-
ty::ScalarInt::try_from_int(
90-
dest_layout.size.sign_extend(discr_val) as i128,
91-
dest_layout.size,
92-
)
93-
.unwrap()
94-
} else {
95-
ty::ScalarInt::try_from_uint(discr_val, dest_layout.size).unwrap()
92+
93+
let val = match dest_layout.ty.kind() {
94+
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
95+
let lsb = fx.bcx.ins().iconst(types::I64, discr_val as u64 as i64);
96+
let msb = fx.bcx.ins().iconst(types::I64, (discr_val >> 64) as u64 as i64);
97+
fx.bcx.ins().iconcat(lsb, msb)
98+
}
99+
ty::Uint(_) | ty::Int(_) => {
100+
let clif_ty = fx.clif_type(dest_layout.ty).unwrap();
101+
let raw_val = dest_layout.size.truncate(discr_val);
102+
fx.bcx.ins().iconst(clif_ty, raw_val as i64)
103+
}
104+
_ => unreachable!(),
96105
};
97-
let res = CValue::const_val(fx, dest_layout, discr_val);
106+
let res = CValue::by_val(val, dest_layout);
98107
dest.write_cvalue(fx, res);
99108
return;
100109
}

‎compiler/rustc_codegen_cranelift/src/driver/aot.rs

+37-35
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_codegen_ssa::errors as ssa_errors;
1515
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind};
1616
use rustc_data_structures::profiling::SelfProfilerRef;
1717
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
18+
use rustc_data_structures::sync::{par_map, IntoDynSyncSend};
1819
use rustc_metadata::fs::copy_to_stdout;
1920
use rustc_metadata::EncodedMetadata;
2021
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
@@ -481,15 +482,16 @@ fn module_codegen(
481482
for (mono_item, _) in mono_items {
482483
match mono_item {
483484
MonoItem::Fn(inst) => {
484-
let codegened_function = crate::base::codegen_fn(
485+
if let Some(codegened_function) = crate::base::codegen_fn(
485486
tcx,
486487
&mut cx,
487488
&mut type_dbg,
488489
Function::new(),
489490
&mut module,
490491
inst,
491-
);
492-
codegened_functions.push(codegened_function);
492+
) {
493+
codegened_functions.push(codegened_function);
494+
}
493495
}
494496
MonoItem::Static(def_id) => {
495497
let data_id = crate::constant::codegen_static(tcx, &mut module, def_id);
@@ -604,39 +606,39 @@ pub(crate) fn run_aot(
604606

605607
let global_asm_config = Arc::new(crate::global_asm::GlobalAsmConfig::new(tcx));
606608

607-
let mut concurrency_limiter = ConcurrencyLimiter::new(tcx.sess, cgus.len());
609+
let (todo_cgus, done_cgus) =
610+
cgus.into_iter().enumerate().partition::<Vec<_>, _>(|&(i, _)| match cgu_reuse[i] {
611+
_ if backend_config.disable_incr_cache => true,
612+
CguReuse::No => true,
613+
CguReuse::PreLto | CguReuse::PostLto => false,
614+
});
615+
616+
let concurrency_limiter = IntoDynSyncSend(ConcurrencyLimiter::new(tcx.sess, todo_cgus.len()));
608617

609618
let modules = tcx.sess.time("codegen mono items", || {
610-
cgus.iter()
611-
.enumerate()
612-
.map(|(i, cgu)| {
613-
let cgu_reuse =
614-
if backend_config.disable_incr_cache { CguReuse::No } else { cgu_reuse[i] };
615-
match cgu_reuse {
616-
CguReuse::No => {
617-
let dep_node = cgu.codegen_dep_node(tcx);
618-
tcx.dep_graph
619-
.with_task(
620-
dep_node,
621-
tcx,
622-
(
623-
backend_config.clone(),
624-
global_asm_config.clone(),
625-
cgu.name(),
626-
concurrency_limiter.acquire(tcx.dcx()),
627-
),
628-
module_codegen,
629-
Some(rustc_middle::dep_graph::hash_result),
630-
)
631-
.0
632-
}
633-
CguReuse::PreLto | CguReuse::PostLto => {
634-
concurrency_limiter.job_already_done();
635-
OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))
636-
}
637-
}
638-
})
639-
.collect::<Vec<_>>()
619+
let mut modules: Vec<_> = par_map(todo_cgus, |(_, cgu)| {
620+
let dep_node = cgu.codegen_dep_node(tcx);
621+
tcx.dep_graph
622+
.with_task(
623+
dep_node,
624+
tcx,
625+
(
626+
backend_config.clone(),
627+
global_asm_config.clone(),
628+
cgu.name(),
629+
concurrency_limiter.acquire(tcx.dcx()),
630+
),
631+
module_codegen,
632+
Some(rustc_middle::dep_graph::hash_result),
633+
)
634+
.0
635+
});
636+
modules.extend(
637+
done_cgus
638+
.into_iter()
639+
.map(|(_, cgu)| OngoingModuleCodegen::Sync(reuse_workproduct_for_cgu(tcx, cgu))),
640+
);
641+
modules
640642
});
641643

642644
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
@@ -705,6 +707,6 @@ pub(crate) fn run_aot(
705707
metadata_module,
706708
metadata,
707709
crate_info: CrateInfo::new(tcx, target_cpu),
708-
concurrency_limiter,
710+
concurrency_limiter: concurrency_limiter.0,
709711
})
710712
}

‎compiler/rustc_codegen_cranelift/src/driver/jit.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ fn create_jit_module(
8383
);
8484

8585
crate::allocator::codegen(tcx, &mut jit_module, &mut cx.unwind_context);
86-
crate::main_shim::maybe_create_entry_wrapper(
87-
tcx,
88-
&mut jit_module,
89-
&mut cx.unwind_context,
90-
true,
91-
true,
92-
);
9386

9487
(jit_module, cx)
9588
}
@@ -153,6 +146,14 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
153146
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
154147
}
155148

149+
crate::main_shim::maybe_create_entry_wrapper(
150+
tcx,
151+
&mut jit_module,
152+
&mut cx.unwind_context,
153+
true,
154+
true,
155+
);
156+
156157
tcx.dcx().abort_if_errors();
157158

158159
jit_module.finalize_definitions().unwrap();
@@ -231,16 +232,16 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
231232
crate::PrintOnPanic(|| format!("{:?} {}", instance, tcx.symbol_name(instance).name));
232233

233234
let cached_func = std::mem::replace(&mut cached_context.func, Function::new());
234-
let codegened_func = crate::base::codegen_fn(
235+
if let Some(codegened_func) = crate::base::codegen_fn(
235236
tcx,
236237
cx,
237238
&mut TypeDebugContext::default(),
238239
cached_func,
239240
module,
240241
instance,
241-
);
242-
243-
crate::base::compile_fn(cx, cached_context, module, codegened_func);
242+
) {
243+
crate::base::compile_fn(cx, cached_context, module, codegened_func);
244+
}
244245
});
245246
}
246247

‎compiler/rustc_codegen_cranelift/src/driver/mod.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! [`codegen_static`]: crate::constant::codegen_static
66
77
use rustc_data_structures::profiling::SelfProfilerRef;
8+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
89
use rustc_middle::mir::mono::{MonoItem, MonoItemData};
910

1011
use crate::prelude::*;
@@ -33,7 +34,20 @@ fn predefine_mono_items<'tcx>(
3334
data.visibility,
3435
is_compiler_builtins,
3536
);
36-
module.declare_function(name, linkage, &sig).unwrap();
37+
let is_naked = tcx
38+
.codegen_fn_attrs(instance.def_id())
39+
.flags
40+
.contains(CodegenFnAttrFlags::NAKED);
41+
module
42+
.declare_function(
43+
name,
44+
// Naked functions are defined in a separate object
45+
// file from the codegen unit rustc expects them to
46+
// be defined in.
47+
if is_naked { Linkage::Import } else { linkage },
48+
&sig,
49+
)
50+
.unwrap();
3751
}
3852
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
3953
}

‎compiler/rustc_codegen_cranelift/src/global_asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
8181
);
8282
}
8383

84-
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
84+
let instance = Instance::mono(tcx, def_id);
8585
let symbol = tcx.symbol_name(instance);
8686
global_asm.push_str(symbol.name);
8787
}

‎compiler/rustc_codegen_cranelift/src/inline_asm.rs

+163-38
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
127127
}
128128
InlineAsmOperand::SymStatic { def_id } => {
129129
assert!(fx.tcx.is_static(def_id));
130-
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
130+
let instance = Instance::mono(fx.tcx, def_id);
131131
CInlineAsmOperand::Symbol { symbol: fx.tcx.symbol_name(instance).name.to_owned() }
132132
}
133133
InlineAsmOperand::Label { .. } => {
@@ -169,6 +169,7 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>(
169169
stack_slots_input: Vec::new(),
170170
stack_slots_output: Vec::new(),
171171
stack_slot_size: Size::from_bytes(0),
172+
is_naked: false,
172173
};
173174
asm_gen.allocate_registers();
174175
asm_gen.allocate_stack_slots();
@@ -209,6 +210,121 @@ pub(crate) fn codegen_inline_asm_inner<'tcx>(
209210
call_inline_asm(fx, &asm_name, asm_gen.stack_slot_size, inputs, outputs);
210211
}
211212

213+
pub(crate) fn codegen_naked_asm<'tcx>(
214+
tcx: TyCtxt<'tcx>,
215+
cx: &mut crate::CodegenCx,
216+
module: &mut dyn Module,
217+
instance: Instance<'tcx>,
218+
span: Span,
219+
symbol_name: &str,
220+
template: &[InlineAsmTemplatePiece],
221+
operands: &[InlineAsmOperand<'tcx>],
222+
options: InlineAsmOptions,
223+
) {
224+
// FIXME add .eh_frame unwind info directives
225+
226+
let operands = operands
227+
.iter()
228+
.map(|operand| match *operand {
229+
InlineAsmOperand::In { .. }
230+
| InlineAsmOperand::Out { .. }
231+
| InlineAsmOperand::InOut { .. } => {
232+
span_bug!(span, "invalid operand type for naked asm")
233+
}
234+
InlineAsmOperand::Const { ref value } => {
235+
let cv = instance.instantiate_mir_and_normalize_erasing_regions(
236+
tcx,
237+
ty::ParamEnv::reveal_all(),
238+
ty::EarlyBinder::bind(value.const_),
239+
);
240+
let const_value = cv
241+
.eval(tcx, ty::ParamEnv::reveal_all(), value.span)
242+
.expect("erroneous constant missed by mono item collection");
243+
244+
let value = rustc_codegen_ssa::common::asm_const_to_str(
245+
tcx,
246+
span,
247+
const_value,
248+
RevealAllLayoutCx(tcx).layout_of(cv.ty()),
249+
);
250+
CInlineAsmOperand::Const { value }
251+
}
252+
InlineAsmOperand::SymFn { ref value } => {
253+
if cfg!(not(feature = "inline_asm_sym")) {
254+
tcx.dcx()
255+
.span_err(span, "asm! and global_asm! sym operands are not yet supported");
256+
}
257+
258+
let const_ = instance.instantiate_mir_and_normalize_erasing_regions(
259+
tcx,
260+
ty::ParamEnv::reveal_all(),
261+
ty::EarlyBinder::bind(value.const_),
262+
);
263+
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
264+
let instance = ty::Instance::resolve_for_fn_ptr(
265+
tcx,
266+
ty::ParamEnv::reveal_all(),
267+
def_id,
268+
args,
269+
)
270+
.unwrap();
271+
let symbol = tcx.symbol_name(instance);
272+
273+
// Pass a wrapper rather than the function itself as the function itself may not
274+
// be exported from the main codegen unit and may thus be unreachable from the
275+
// object file created by an external assembler.
276+
let inline_asm_index = cx.inline_asm_index.get();
277+
cx.inline_asm_index.set(inline_asm_index + 1);
278+
let wrapper_name = format!(
279+
"__inline_asm_{}_wrapper_n{}",
280+
cx.cgu_name.as_str().replace('.', "__").replace('-', "_"),
281+
inline_asm_index
282+
);
283+
let sig =
284+
get_function_sig(tcx, module.target_config().default_call_conv, instance);
285+
create_wrapper_function(
286+
module,
287+
&mut cx.unwind_context,
288+
sig,
289+
&wrapper_name,
290+
symbol.name,
291+
);
292+
293+
CInlineAsmOperand::Symbol { symbol: wrapper_name }
294+
} else {
295+
span_bug!(span, "invalid type for asm sym (fn)");
296+
}
297+
}
298+
InlineAsmOperand::SymStatic { def_id } => {
299+
assert!(tcx.is_static(def_id));
300+
let instance = Instance::mono(tcx, def_id);
301+
CInlineAsmOperand::Symbol { symbol: tcx.symbol_name(instance).name.to_owned() }
302+
}
303+
InlineAsmOperand::Label { .. } => {
304+
span_bug!(span, "asm! label operands are not yet supported");
305+
}
306+
})
307+
.collect::<Vec<_>>();
308+
309+
let asm_gen = InlineAssemblyGenerator {
310+
tcx,
311+
arch: tcx.sess.asm_arch.unwrap(),
312+
enclosing_def_id: instance.def_id(),
313+
template,
314+
operands: &operands,
315+
options,
316+
registers: Vec::new(),
317+
stack_slots_clobber: Vec::new(),
318+
stack_slots_input: Vec::new(),
319+
stack_slots_output: Vec::new(),
320+
stack_slot_size: Size::from_bytes(0),
321+
is_naked: true,
322+
};
323+
324+
let generated_asm = asm_gen.generate_asm_wrapper(symbol_name);
325+
cx.global_asm.push_str(&generated_asm);
326+
}
327+
212328
struct InlineAssemblyGenerator<'a, 'tcx> {
213329
tcx: TyCtxt<'tcx>,
214330
arch: InlineAsmArch,
@@ -221,10 +337,13 @@ struct InlineAssemblyGenerator<'a, 'tcx> {
221337
stack_slots_input: Vec<Option<Size>>,
222338
stack_slots_output: Vec<Option<Size>>,
223339
stack_slot_size: Size,
340+
is_naked: bool,
224341
}
225342

226343
impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
227344
fn allocate_registers(&mut self) {
345+
assert!(!self.is_naked);
346+
228347
let sess = self.tcx.sess;
229348
let map = allocatable_registers(
230349
self.arch,
@@ -348,6 +467,8 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
348467
}
349468

350469
fn allocate_stack_slots(&mut self) {
470+
assert!(!self.is_naked);
471+
351472
let mut slot_size = Size::from_bytes(0);
352473
let mut slots_clobber = vec![None; self.operands.len()];
353474
let mut slots_input = vec![None; self.operands.len()];
@@ -468,30 +589,32 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
468589
if is_x86 {
469590
generated_asm.push_str(".intel_syntax noprefix\n");
470591
}
471-
Self::prologue(&mut generated_asm, self.arch);
592+
if !self.is_naked {
593+
Self::prologue(&mut generated_asm, self.arch);
594+
595+
// Save clobbered registers
596+
if !self.options.contains(InlineAsmOptions::NORETURN) {
597+
for (reg, slot) in self
598+
.registers
599+
.iter()
600+
.zip(self.stack_slots_clobber.iter().copied())
601+
.filter_map(|(r, s)| r.zip(s))
602+
{
603+
Self::save_register(&mut generated_asm, self.arch, reg, slot);
604+
}
605+
}
472606

473-
// Save clobbered registers
474-
if !self.options.contains(InlineAsmOptions::NORETURN) {
607+
// Write input registers
475608
for (reg, slot) in self
476609
.registers
477610
.iter()
478-
.zip(self.stack_slots_clobber.iter().copied())
611+
.zip(self.stack_slots_input.iter().copied())
479612
.filter_map(|(r, s)| r.zip(s))
480613
{
481-
Self::save_register(&mut generated_asm, self.arch, reg, slot);
614+
Self::restore_register(&mut generated_asm, self.arch, reg, slot);
482615
}
483616
}
484617

485-
// Write input registers
486-
for (reg, slot) in self
487-
.registers
488-
.iter()
489-
.zip(self.stack_slots_input.iter().copied())
490-
.filter_map(|(r, s)| r.zip(s))
491-
{
492-
Self::restore_register(&mut generated_asm, self.arch, reg, slot);
493-
}
494-
495618
if is_x86 && self.options.contains(InlineAsmOptions::ATT_SYNTAX) {
496619
generated_asm.push_str(".att_syntax\n");
497620
}
@@ -553,30 +676,32 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
553676
generated_asm.push_str(".intel_syntax noprefix\n");
554677
}
555678

556-
if !self.options.contains(InlineAsmOptions::NORETURN) {
557-
// Read output registers
558-
for (reg, slot) in self
559-
.registers
560-
.iter()
561-
.zip(self.stack_slots_output.iter().copied())
562-
.filter_map(|(r, s)| r.zip(s))
563-
{
564-
Self::save_register(&mut generated_asm, self.arch, reg, slot);
565-
}
679+
if !self.is_naked {
680+
if !self.options.contains(InlineAsmOptions::NORETURN) {
681+
// Read output registers
682+
for (reg, slot) in self
683+
.registers
684+
.iter()
685+
.zip(self.stack_slots_output.iter().copied())
686+
.filter_map(|(r, s)| r.zip(s))
687+
{
688+
Self::save_register(&mut generated_asm, self.arch, reg, slot);
689+
}
566690

567-
// Restore clobbered registers
568-
for (reg, slot) in self
569-
.registers
570-
.iter()
571-
.zip(self.stack_slots_clobber.iter().copied())
572-
.filter_map(|(r, s)| r.zip(s))
573-
{
574-
Self::restore_register(&mut generated_asm, self.arch, reg, slot);
575-
}
691+
// Restore clobbered registers
692+
for (reg, slot) in self
693+
.registers
694+
.iter()
695+
.zip(self.stack_slots_clobber.iter().copied())
696+
.filter_map(|(r, s)| r.zip(s))
697+
{
698+
Self::restore_register(&mut generated_asm, self.arch, reg, slot);
699+
}
576700

577-
Self::epilogue(&mut generated_asm, self.arch);
578-
} else {
579-
Self::epilogue_noreturn(&mut generated_asm, self.arch);
701+
Self::epilogue(&mut generated_asm, self.arch);
702+
} else {
703+
Self::epilogue_noreturn(&mut generated_asm, self.arch);
704+
}
580705
}
581706

582707
if is_x86 {

‎compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

+52
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,21 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
374374
}
375375
}
376376
}
377+
"llvm.x86.avx2.permd" => {
378+
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_permutevar8x32_epi32
379+
intrinsic_args!(fx, args => (a, idx); intrinsic);
380+
381+
for j in 0..=7 {
382+
let index = idx.value_typed_lane(fx, fx.tcx.types.u32, j).load_scalar(fx);
383+
let index = fx.bcx.ins().uextend(fx.pointer_type, index);
384+
let value = a.value_lane_dyn(fx, index).load_scalar(fx);
385+
ret.place_typed_lane(fx, fx.tcx.types.u32, j).to_ptr().store(
386+
fx,
387+
value,
388+
MemFlags::trusted(),
389+
);
390+
}
391+
}
377392
"llvm.x86.avx2.vperm2i128"
378393
| "llvm.x86.avx.vperm2f128.ps.256"
379394
| "llvm.x86.avx.vperm2f128.pd.256" => {
@@ -832,6 +847,43 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
832847
}
833848
}
834849

850+
"llvm.x86.sse42.crc32.32.8"
851+
| "llvm.x86.sse42.crc32.32.16"
852+
| "llvm.x86.sse42.crc32.32.32"
853+
| "llvm.x86.sse42.crc32.64.64" => {
854+
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#ig_expand=1419&text=_mm_crc32_u32
855+
intrinsic_args!(fx, args => (crc, v); intrinsic);
856+
857+
let crc = crc.load_scalar(fx);
858+
let v = v.load_scalar(fx);
859+
860+
let asm = match intrinsic {
861+
"llvm.x86.sse42.crc32.32.8" => "crc32 eax, dl",
862+
"llvm.x86.sse42.crc32.32.16" => "crc32 eax, dx",
863+
"llvm.x86.sse42.crc32.32.32" => "crc32 eax, edx",
864+
"llvm.x86.sse42.crc32.64.64" => "crc32 rax, rdx",
865+
_ => unreachable!(),
866+
};
867+
868+
codegen_inline_asm_inner(
869+
fx,
870+
&[InlineAsmTemplatePiece::String(asm.to_string())],
871+
&[
872+
CInlineAsmOperand::InOut {
873+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
874+
_late: true,
875+
in_value: crc,
876+
out_place: Some(ret),
877+
},
878+
CInlineAsmOperand::In {
879+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
880+
value: v,
881+
},
882+
],
883+
InlineAsmOptions::NOSTACK | InlineAsmOptions::PURE | InlineAsmOptions::NOMEM,
884+
);
885+
}
886+
835887
"llvm.x86.sse42.pcmpestri128" => {
836888
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cmpestri&ig_expand=939
837889
intrinsic_args!(fx, args => (a, la, b, lb, _imm8); intrinsic);

‎compiler/rustc_codegen_cranelift/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn TargetIs
331331
sess.dcx().fatal(format!("can't compile for {}: {}", target_triple, err));
332332
});
333333
if target_triple.architecture == target_lexicon::Architecture::X86_64 {
334-
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
335-
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.
336-
builder.enable("nehalem").unwrap();
334+
// Only set the target cpu on x86_64 as Cranelift is missing
335+
// the target cpu list for most other targets.
336+
builder.enable(sess.target.cpu.as_ref()).unwrap();
337337
}
338338
builder
339339
}

‎compiler/rustc_codegen_cranelift/src/main_shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn maybe_create_entry_wrapper(
2929

3030
if main_def_id.is_local() {
3131
let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx);
32-
if !is_jit && module.get_name(tcx.symbol_name(instance).name).is_none() {
32+
if module.get_name(tcx.symbol_name(instance).name).is_none() {
3333
return;
3434
}
3535
} else if !is_primary_cgu {

‎compiler/rustc_codegen_cranelift/src/value_and_place.rs

-8
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,6 @@ impl<'tcx> CValue<'tcx> {
317317

318318
let clif_ty = fx.clif_type(layout.ty).unwrap();
319319

320-
if let ty::Bool = layout.ty.kind() {
321-
assert!(
322-
const_val == ty::ScalarInt::FALSE || const_val == ty::ScalarInt::TRUE,
323-
"Invalid bool 0x{:032X}",
324-
const_val
325-
);
326-
}
327-
328320
let val = match layout.ty.kind() {
329321
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
330322
let const_val = const_val.assert_bits(layout.size);

‎compiler/rustc_codegen_cranelift/y.cmd

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@echo off
22
echo [BUILD] build system >&2
3-
mkdir build 2>nul
4-
rustc build_system/main.rs -o build\y.exe -Cdebuginfo=1 --edition 2021 || goto :error
5-
build\y.exe %* || goto :error
3+
cargo run --manifest-path build_system/Cargo.toml -- %* || goto :error
64
goto :EOF
75

86
:error

‎compiler/rustc_codegen_cranelift/y.ps1

100644100755
+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
$ErrorActionPreference = "Stop"
22

33
$host.ui.WriteErrorLine("[BUILD] build system")
4-
New-Item -ItemType Directory -Force -Path build | Out-Null
5-
& rustc build_system/main.rs -o build\y.exe -Cdebuginfo=1 --edition 2021
6-
if ($LASTEXITCODE -ne 0) {
7-
exit $LASTEXITCODE
8-
}
9-
& build\y.exe $args
4+
& cargo run --manifest-path build_system/Cargo.toml -- $args
105
if ($LASTEXITCODE -ne 0) {
116
exit $LASTEXITCODE
127
}

‎compiler/rustc_codegen_cranelift/y.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
set -e
44
echo "[BUILD] build system" 1>&2
5-
rustc build_system/main.rs -o y.bin -Cdebuginfo=1 --edition 2021
6-
exec ./y.bin "$@"
5+
exec cargo run --manifest-path build_system/Cargo.toml -- "$@"

0 commit comments

Comments
 (0)
Please sign in to comment.