Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c073f56

Browse files
committedJan 26, 2024
Auto merge of rust-lang#120395 - bjorn3:sync_cg_clif-2024-01-26, r=bjorn3
Subtree sync for rustc_codegen_cranelift A couple of fixes as well as an update to Cranelift 0.104, which includes a fix for the ABI of `Option<u128>`. r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents e7bbe8c + 3701802 commit c073f56

File tree

24 files changed

+434
-323
lines changed

24 files changed

+434
-323
lines changed
 

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ jobs:
3333
TARGET_TRIPLE: x86_64-pc-windows-gnu
3434

3535
steps:
36-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
3737

3838
- name: CPU features
3939
if: matrix.os == 'ubuntu-latest'
4040
run: cat /proc/cpuinfo
4141

4242
- name: Cache cargo target dir
43-
uses: actions/cache@v3
43+
uses: actions/cache@v4
4444
with:
4545
path: build/cg_clif
4646
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

‎compiler/rustc_codegen_cranelift/.github/workflows/audit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
audit:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- run: |
1515
sed -i 's/components.*/components = []/' rust-toolchain
1616
echo 'profile = "minimal"' >> rust-toolchain

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
timeout-minutes: 10
1111

1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414

1515
- name: Avoid installing rustc-dev
1616
run: |
@@ -64,14 +64,14 @@ jobs:
6464
TARGET_TRIPLE: x86_64-pc-windows-gnu
6565

6666
steps:
67-
- uses: actions/checkout@v3
67+
- uses: actions/checkout@v4
6868

6969
- name: CPU features
7070
if: matrix.os == 'ubuntu-latest'
7171
run: cat /proc/cpuinfo
7272

7373
- name: Cache cargo target dir
74-
uses: actions/cache@v3
74+
uses: actions/cache@v4
7575
with:
7676
path: build/cg_clif
7777
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@@ -138,7 +138,7 @@ jobs:
138138
shell: bash
139139

140140
steps:
141-
- uses: actions/checkout@v3
141+
- uses: actions/checkout@v4
142142

143143
- name: CPU features
144144
run: cat /proc/cpuinfo
@@ -164,13 +164,13 @@ jobs:
164164
shell: bash
165165

166166
steps:
167-
- uses: actions/checkout@v3
167+
- uses: actions/checkout@v4
168168

169169
- name: CPU features
170170
run: cat /proc/cpuinfo
171171

172172
- name: Cache cargo target dir
173-
uses: actions/cache@v3
173+
uses: actions/cache@v4
174174
with:
175175
path: build/cg_clif
176176
key: ${{ runner.os }}-x86_64-unknown-linux-gnu-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@@ -221,10 +221,10 @@ jobs:
221221
TARGET_TRIPLE: x86_64-pc-windows-gnu
222222

223223
steps:
224-
- uses: actions/checkout@v3
224+
- uses: actions/checkout@v4
225225

226226
- name: Cache cargo target dir
227-
uses: actions/cache@v3
227+
uses: actions/cache@v4
228228
with:
229229
path: build/cg_clif
230230
key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-dist-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@@ -276,7 +276,7 @@ jobs:
276276
cancel-in-progress: true
277277

278278
steps:
279-
- uses: actions/checkout@v3
279+
- uses: actions/checkout@v4
280280

281281
- name: Download all built artifacts
282282
uses: actions/download-artifact@v4

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
timeout-minutes: 60
1010

1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313

1414
- name: CPU features
1515
run: cat /proc/cpuinfo
1616

1717
- name: Cache cargo target dir
18-
uses: actions/cache@v3
18+
uses: actions/cache@v4
1919
with:
2020
path: build/cg_clif
2121
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
@@ -32,13 +32,13 @@ jobs:
3232
timeout-minutes: 60
3333

3434
steps:
35-
- uses: actions/checkout@v3
35+
- uses: actions/checkout@v4
3636

3737
- name: CPU features
3838
run: cat /proc/cpuinfo
3939

4040
- name: Cache cargo target dir
41-
uses: actions/cache@v3
41+
uses: actions/cache@v4
4242
with:
4343
path: build/cg_clif
4444
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

‎compiler/rustc_codegen_cranelift/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"editor.formatOnSave": true,
33

4-
// source for rustc_* is not included in the rust-src component; disable the errors about this
4+
// in case rustc.source is disabled for performance reasons; disable the errors about this
55
"rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"],
6+
"rust-analyzer.rustc.source": "discover",
67
"rust-analyzer.imports.granularity.enforce": true,
78
"rust-analyzer.imports.granularity.group": "module",
89
"rust-analyzer.imports.prefix": "crate",

‎compiler/rustc_codegen_cranelift/Cargo.lock

Lines changed: 103 additions & 37 deletions
Original file line numberDiff line numberDiff line change

‎compiler/rustc_codegen_cranelift/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ crate-type = ["dylib"]
88

99
[dependencies]
1010
# These have to be in sync with each other
11-
cranelift-codegen = { version = "0.103", default-features = false, features = ["std", "unwind", "all-arch"] }
12-
cranelift-frontend = { version = "0.103" }
13-
cranelift-module = { version = "0.103" }
14-
cranelift-native = { version = "0.103" }
15-
cranelift-jit = { version = "0.103", optional = true }
16-
cranelift-object = { version = "0.103" }
11+
cranelift-codegen = { version = "0.104", default-features = false, features = ["std", "unwind", "all-arch"] }
12+
cranelift-frontend = { version = "0.104" }
13+
cranelift-module = { version = "0.104" }
14+
cranelift-native = { version = "0.104" }
15+
cranelift-jit = { version = "0.104", optional = true }
16+
cranelift-object = { version = "0.104" }
1717
target-lexicon = "0.12.0"
1818
gimli = { version = "0.28", default-features = false, features = ["write"]}
1919
object = { version = "0.32", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

‎compiler/rustc_codegen_cranelift/Readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ $ ./test.sh
6262

6363
For more docs on how to build and test see [build_system/usage.txt](build_system/usage.txt) or the help message of `./y.sh`.
6464

65+
## Platform support
66+
67+
|OS \ architecture|x86\_64|AArch64|Riscv64|s390x (System-Z)|
68+
|---|---|---|---|---|
69+
|Linux|||[^no-rustup]|[^no-rustup]|
70+
|FreeBSD|[^no-rustup]||||
71+
|AIX|[^xcoff]|N/A|N/A|[^xcoff]|
72+
|Other unixes|||||
73+
|macOS||[^apple-silicon]|N/A|N/A|
74+
|Windows|[^no-rustup]||N/A|N/A|
75+
76+
✅: Fully supported and tested
77+
❓: Maybe supported, not tested
78+
❌: Not supported at all
79+
80+
Not all targets are available as rustup component for nightly. See notes in the platform support matrix.
81+
82+
[^xcoff]: XCOFF object file format is not supported.
83+
[^apple-silicon]: Tracked in [#1248](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1248).
84+
[^no-rustup]: Not available as rustup component for nightly. You can build it yourself.
85+
6586
## Usage
6687

6788
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
@@ -100,6 +121,8 @@ You need to do this steps to successfully compile and use the cranelift backend
100121
* (Optional) run tests: `rustup run stage2 ./y.sh test`
101122
8. Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like `$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release`.
102123

124+
You can also set `rust-analyzer.rustc.source` to your rust workspace to get rust-analyzer to understand your changes.
125+
103126
## Configuration
104127

105128
See the documentation on the `BackendConfig` struct in [config.rs](src/config.rs) for all

‎compiler/rustc_codegen_cranelift/build_system/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
113113
pub(crate) static RAND_REPO: GitRepo = GitRepo::github(
114114
"rust-random",
115115
"rand",
116-
"9a02c819cc1e4ec6959ae25eafbb5cf6acb68234",
117-
"4934f0afb1d1c2ca",
116+
"1f4507a8e1cf8050e4ceef95eeda8f64645b6719",
117+
"981f8bf489338978",
118118
"rand",
119119
);
120120

@@ -133,8 +133,8 @@ pub(crate) static REGEX: CargoProject = CargoProject::new(&REGEX_REPO.source_dir
133133
pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
134134
"rust-lang",
135135
"portable-simd",
136-
"4825b2a64d765317066948867e8714674419359b",
137-
"9e67d07c00f5fb0b",
136+
"97007cc2e70df8c97326ce896a79e2f0ce4dd98b",
137+
"e54a16035cedf205",
138138
"portable-simd",
139139
);
140140

‎compiler/rustc_codegen_cranelift/patches/0001-portable-simd-Enable-the-exposed_provenance-feature.patch

Lines changed: 0 additions & 22 deletions
This file was deleted.

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ dependencies = [
487487
"rand_pcg",
488488
"rayon",
489489
"serde",
490+
"zerocopy",
490491
]
491492

492493
[[package]]
@@ -505,6 +506,7 @@ version = "0.7.0"
505506
dependencies = [
506507
"getrandom",
507508
"serde",
509+
"zerocopy",
508510
]
509511

510512
[[package]]
@@ -525,6 +527,7 @@ name = "rand_pcg"
525527
version = "0.4.0"
526528
dependencies = [
527529
"bincode",
530+
"rand",
528531
"rand_core",
529532
"serde",
530533
]
@@ -823,3 +826,23 @@ name = "winapi-x86_64-pc-windows-gnu"
823826
version = "0.4.0"
824827
source = "registry+https://github.com/rust-lang/crates.io-index"
825828
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
829+
830+
[[package]]
831+
name = "zerocopy"
832+
version = "0.7.32"
833+
source = "registry+https://github.com/rust-lang/crates.io-index"
834+
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
835+
dependencies = [
836+
"zerocopy-derive",
837+
]
838+
839+
[[package]]
840+
name = "zerocopy-derive"
841+
version = "0.7.32"
842+
source = "registry+https://github.com/rust-lang/crates.io-index"
843+
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
844+
dependencies = [
845+
"proc-macro2",
846+
"quote",
847+
"syn 2.0.37",
848+
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ dependencies = [
6161

6262
[[package]]
6363
name = "compiler_builtins"
64-
version = "0.1.104"
64+
version = "0.1.106"
6565
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "99c3f9035afc33f4358773239573f7d121099856753e1bbd2a6a5207098fc741"
66+
checksum = "f4ab134a739bafec76aa91ccb15d519a54e569350644a1fea6528d5a0d407e22"
6767
dependencies = [
6868
"cc",
6969
"rustc-std-workspace-core",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-12-31"
2+
channel = "nightly-2024-01-26"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ use gimli::write::{
1313
};
1414
use gimli::{Encoding, Format, LineEncoding, RunTimeEndian};
1515
use indexmap::IndexSet;
16+
use rustc_session::Session;
1617

1718
pub(crate) use self::emit::{DebugReloc, DebugRelocName};
1819
pub(crate) use self::unwind::UnwindContext;
1920
use crate::prelude::*;
2021

21-
pub(crate) fn producer() -> String {
22-
format!(
23-
"rustc version {} with cranelift {}",
24-
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
25-
cranelift_codegen::VERSION,
26-
)
22+
pub(crate) fn producer(sess: &Session) -> String {
23+
format!("rustc version {} with cranelift {}", sess.cfg_version, cranelift_codegen::VERSION)
2724
}
2825

2926
pub(crate) struct DebugContext {
@@ -67,7 +64,7 @@ impl DebugContext {
6764

6865
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
6966

70-
let producer = producer();
67+
let producer = producer(tcx.sess);
7168
let comp_dir = tcx
7269
.sess
7370
.opts

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ fn emit_cgu(
143143
debug: Option<DebugContext>,
144144
unwind_context: UnwindContext,
145145
global_asm_object_file: Option<PathBuf>,
146+
producer: &str,
146147
) -> Result<ModuleCodegenResult, String> {
147148
let mut product = module.finish();
148149

@@ -152,8 +153,14 @@ fn emit_cgu(
152153

153154
unwind_context.emit(&mut product);
154155

155-
let module_regular =
156-
emit_module(output_filenames, prof, product.object, ModuleKind::Regular, name.clone())?;
156+
let module_regular = emit_module(
157+
output_filenames,
158+
prof,
159+
product.object,
160+
ModuleKind::Regular,
161+
name.clone(),
162+
producer,
163+
)?;
157164

158165
Ok(ModuleCodegenResult {
159166
module_regular,
@@ -174,6 +181,7 @@ fn emit_module(
174181
mut object: cranelift_object::object::write::Object<'_>,
175182
kind: ModuleKind,
176183
name: String,
184+
producer_str: &str,
177185
) -> Result<CompiledModule, String> {
178186
if object.format() == cranelift_object::object::BinaryFormat::Elf {
179187
let comment_section = object.add_section(
@@ -182,7 +190,7 @@ fn emit_module(
182190
cranelift_object::object::SectionKind::OtherString,
183191
);
184192
let mut producer = vec![0];
185-
producer.extend(crate::debuginfo::producer().as_bytes());
193+
producer.extend(producer_str.as_bytes());
186194
producer.push(0);
187195
object.set_section_data(comment_section, producer, 1);
188196
}
@@ -321,6 +329,8 @@ fn module_codegen(
321329
(cgu_name, cx, module, codegened_functions)
322330
});
323331

332+
let producer = crate::debuginfo::producer(tcx.sess);
333+
324334
OngoingModuleCodegen::Async(std::thread::spawn(move || {
325335
cx.profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
326336
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
@@ -348,6 +358,7 @@ fn module_codegen(
348358
cx.debug_context,
349359
cx.unwind_context,
350360
global_asm_object_file,
361+
&producer,
351362
)
352363
});
353364
std::mem::drop(token);
@@ -453,6 +464,7 @@ pub(crate) fn run_aot(
453464
product.object,
454465
ModuleKind::Allocator,
455466
"allocator_shim".to_owned(),
467+
&crate::debuginfo::producer(tcx.sess),
456468
) {
457469
Ok(allocator_module) => Some(allocator_module),
458470
Err(err) => tcx.dcx().fatal(err),
@@ -467,7 +479,7 @@ pub(crate) fn run_aot(
467479

468480
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
469481
let metadata_cgu_name = cgu_name_builder
470-
.build_cgu_name(LOCAL_CRATE, &["crate"], Some("metadata"))
482+
.build_cgu_name(LOCAL_CRATE, ["crate"], Some("metadata"))
471483
.as_str()
472484
.to_string();
473485

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,9 @@ fn dep_symbol_lookup_fn(
321321
Linkage::NotLinked | Linkage::IncludedFromDylib => {}
322322
Linkage::Static => {
323323
let name = crate_info.crate_name[&cnum];
324-
sess.dcx()
325-
.struct_err(format!("Can't load static lib {}", name))
326-
.note("rustc_codegen_cranelift can only load dylibs in JIT mode.")
327-
.emit();
324+
let mut diag = sess.dcx().struct_err(format!("Can't load static lib {}", name));
325+
diag.note("rustc_codegen_cranelift can only load dylibs in JIT mode.");
326+
diag.emit();
328327
}
329328
Linkage::Dynamic => {
330329
dylib_paths.push(src.dylib.as_ref().unwrap().0.clone());

‎compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
5252
}
5353

5454
let operands = operands
55-
.into_iter()
55+
.iter()
5656
.map(|operand| match *operand {
5757
InlineAsmOperand::In { reg, ref value } => CInlineAsmOperand::In {
5858
reg,
@@ -506,10 +506,34 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
506506
if self.options.contains(InlineAsmOptions::ATT_SYNTAX) {
507507
generated_asm.push('%');
508508
}
509-
self.registers[*operand_idx]
510-
.unwrap()
511-
.emit(&mut generated_asm, self.arch, *modifier)
512-
.unwrap();
509+
510+
let reg = self.registers[*operand_idx].unwrap();
511+
match self.arch {
512+
InlineAsmArch::X86_64 => match reg {
513+
InlineAsmReg::X86(reg)
514+
if reg as u32 >= X86InlineAsmReg::xmm0 as u32
515+
&& reg as u32 <= X86InlineAsmReg::xmm15 as u32 =>
516+
{
517+
// rustc emits x0 rather than xmm0
518+
let class = match *modifier {
519+
None | Some('x') => "xmm",
520+
Some('y') => "ymm",
521+
Some('z') => "zmm",
522+
_ => unreachable!(),
523+
};
524+
write!(
525+
generated_asm,
526+
"{class}{}",
527+
reg as u32 - X86InlineAsmReg::xmm0 as u32
528+
)
529+
.unwrap();
530+
}
531+
_ => reg
532+
.emit(&mut generated_asm, InlineAsmArch::X86_64, *modifier)
533+
.unwrap(),
534+
},
535+
_ => reg.emit(&mut generated_asm, self.arch, *modifier).unwrap(),
536+
}
513537
}
514538
CInlineAsmOperand::Const { ref value } => {
515539
generated_asm.push_str(value);
@@ -739,7 +763,7 @@ fn call_inline_asm<'tcx>(
739763
},
740764
)
741765
.unwrap();
742-
let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, &mut fx.bcx.func);
766+
let inline_asm_func = fx.module.declare_func_in_func(inline_asm_func, fx.bcx.func);
743767
if fx.clif_comments.enabled() {
744768
fx.add_comment(inline_asm_func, asm_name);
745769
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
3535
}
3636

3737
match intrinsic {
38+
"llvm.prefetch" => {
39+
// Nothing to do. This is merely a perf hint.
40+
}
41+
3842
_ if intrinsic.starts_with("llvm.ctlz.v") => {
3943
intrinsic_args!(fx, args => (a); intrinsic);
4044

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
243243
}
244244

245245
// FIXME generalize vector types
246+
"llvm.aarch64.neon.tbl1.v8i8" => {
247+
intrinsic_args!(fx, args => (t, idx); intrinsic);
248+
249+
let zero = fx.bcx.ins().iconst(types::I8, 0);
250+
for i in 0..8 {
251+
let idx_lane = idx.value_lane(fx, i).load_scalar(fx);
252+
let is_zero =
253+
fx.bcx.ins().icmp_imm(IntCC::UnsignedGreaterThanOrEqual, idx_lane, 16);
254+
let t_idx = fx.bcx.ins().uextend(fx.pointer_type, idx_lane);
255+
let t_lane = t.value_lane_dyn(fx, t_idx).load_scalar(fx);
256+
let res = fx.bcx.ins().select(is_zero, zero, t_lane);
257+
ret.place_lane(fx, i).to_ptr().store(fx, res, MemFlags::trusted());
258+
}
259+
}
246260
"llvm.aarch64.neon.tbl1.v16i8" => {
247261
intrinsic_args!(fx, args => (t, idx); intrinsic);
248262

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

Lines changed: 134 additions & 196 deletions
Large diffs are not rendered by default.

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
293293
}
294294

295295
ret.write_cvalue(fx, base);
296-
let ret_lane = ret.place_lane(fx, idx.try_into().unwrap());
296+
let ret_lane = ret.place_lane(fx, idx.into());
297297
ret_lane.write_cvalue(fx, val);
298298
}
299299

@@ -340,7 +340,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
340340
);
341341
}
342342

343-
let ret_lane = v.value_lane(fx, idx.try_into().unwrap());
343+
let ret_lane = v.value_lane(fx, idx.into());
344344
ret.write_cvalue(fx, ret_lane);
345345
}
346346

@@ -822,7 +822,35 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
822822
let (lane_count, lane_ty) = a.layout().ty.simd_size_and_type(fx.tcx);
823823
let lane_layout = fx.layout_of(lane_ty);
824824

825-
let m = m.load_scalar(fx);
825+
let expected_int_bits = lane_count.max(8);
826+
let expected_bytes = expected_int_bits / 8 + ((expected_int_bits % 8 > 0) as u64);
827+
828+
let m = match m.layout().ty.kind() {
829+
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => m.load_scalar(fx),
830+
ty::Array(elem, len)
831+
if matches!(elem.kind(), ty::Uint(ty::UintTy::U8))
832+
&& len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
833+
== Some(expected_bytes) =>
834+
{
835+
m.force_stack(fx).0.load(
836+
fx,
837+
Type::int(expected_int_bits as u16).unwrap(),
838+
MemFlags::trusted(),
839+
)
840+
}
841+
_ => {
842+
fx.tcx.dcx().span_fatal(
843+
span,
844+
format!(
845+
"invalid monomorphization of `simd_select_bitmask` intrinsic: \
846+
cannot accept `{}` as mask, expected `u{}` or `[u8; {}]`",
847+
ret.layout().ty,
848+
expected_int_bits,
849+
expected_bytes
850+
),
851+
);
852+
}
853+
};
826854

827855
for lane in 0..lane_count {
828856
let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(lane) as i64);

‎compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern crate rustc_fs_util;
1818
extern crate rustc_hir;
1919
extern crate rustc_incremental;
2020
extern crate rustc_index;
21-
extern crate rustc_interface;
2221
extern crate rustc_metadata;
2322
extern crate rustc_session;
2423
extern crate rustc_span;
@@ -42,7 +41,7 @@ use rustc_metadata::EncodedMetadata;
4241
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4342
use rustc_session::config::OutputFilenames;
4443
use rustc_session::Session;
45-
use rustc_span::Symbol;
44+
use rustc_span::{sym, Symbol};
4645

4746
pub use crate::config::*;
4847
use crate::prelude::*;
@@ -190,8 +189,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
190189
}
191190
}
192191

193-
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
194-
vec![] // FIXME necessary for #[cfg(target_feature]
192+
fn target_features(&self, sess: &Session, _allow_unstable: bool) -> Vec<rustc_span::Symbol> {
193+
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
194+
if sess.target.arch == "x86_64" && sess.target.os != "none" {
195+
// x86_64 mandates SSE2 support
196+
vec![Symbol::intern("fxsr"), sym::sse, Symbol::intern("sse2")]
197+
} else if sess.target.arch == "aarch64" && sess.target.os != "none" {
198+
// AArch64 mandates Neon support
199+
vec![sym::neon]
200+
} else {
201+
vec![]
202+
}
195203
}
196204

197205
fn print_version(&self) {
@@ -305,16 +313,13 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::Tar
305313
let flags = settings::Flags::new(flags_builder);
306314

307315
let isa_builder = match sess.opts.cg.target_cpu.as_deref() {
308-
Some("native") => {
309-
let builder = cranelift_native::builder_with_options(true).unwrap();
310-
builder
311-
}
316+
Some("native") => cranelift_native::builder_with_options(true).unwrap(),
312317
Some(value) => {
313318
let mut builder =
314319
cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| {
315320
sess.dcx().fatal(format!("can't compile for {}: {}", target_triple, err));
316321
});
317-
if let Err(_) = builder.enable(value) {
322+
if builder.enable(value).is_err() {
318323
sess.dcx()
319324
.fatal("the specified target cpu isn't currently supported by Cranelift.");
320325
}

‎compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ pub(crate) fn unsized_info<'tcx>(
2828
.bcx
2929
.ins()
3030
.iconst(fx.pointer_type, len.eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64),
31-
(
32-
&ty::Dynamic(ref data_a, _, src_dyn_kind),
33-
&ty::Dynamic(ref data_b, _, target_dyn_kind),
34-
) if src_dyn_kind == target_dyn_kind => {
31+
(&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind))
32+
if src_dyn_kind == target_dyn_kind =>
33+
{
3534
let old_info =
3635
old_info.expect("unsized_info: missing old info for trait upcasting coercion");
3736
if data_a.principal_def_id() == data_b.principal_def_id() {

‎compiler/rustc_codegen_cranelift/src/vtable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub(crate) fn get_vtable<'tcx>(
9595
let alloc_id = fx.tcx.vtable_allocation((ty, trait_ref));
9696
let data_id =
9797
data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, Mutability::Not);
98-
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
98+
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
9999
if fx.clif_comments.enabled() {
100100
fx.add_comment(local_data_id, format!("vtable: {:?}", alloc_id));
101101
}

0 commit comments

Comments
 (0)
This repository has been archived.