Skip to content

Commit a302610

Browse files
committed
Merge commit '93a5433f17ab5ed48cc88f1e69b0713b16183373' into sync_cg_clif-2023-10-24
1 parent e472b55 commit a302610

14 files changed

+260
-138
lines changed

Diff for: .vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
]
3434
},
3535
{
36-
"sysroot_src": "./download/sysroot/sysroot_src/library",
36+
"sysroot_src": "./build/stdlib/library",
3737
"crates": [
3838
{
3939
"root_module": "./example/std_example.rs",

Diff for: Cargo.lock

+26-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+6-6
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.101", features = ["unwind", "all-arch"] }
12-
cranelift-frontend = { version = "0.101" }
13-
cranelift-module = { version = "0.101" }
14-
cranelift-native = { version = "0.101" }
15-
cranelift-jit = { version = "0.101", optional = true }
16-
cranelift-object = { version = "0.101" }
11+
cranelift-codegen = { version = "0.101.1", features = ["unwind", "all-arch"] }
12+
cranelift-frontend = { version = "0.101.1" }
13+
cranelift-module = { version = "0.101.1" }
14+
cranelift-native = { version = "0.101.1" }
15+
cranelift-jit = { version = "0.101.1", optional = true }
16+
cranelift-object = { version = "0.101.1" }
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"] }

Diff for: Readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If not please open an issue.
88
## Building and testing
99

1010
```bash
11-
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift
11+
$ git clone https://github.com/rust-lang/rustc_codegen_cranelift
1212
$ cd rustc_codegen_cranelift
1313
$ ./y.sh prepare
1414
$ ./y.sh build
@@ -29,7 +29,7 @@ Extract the `dist` directory in the archive anywhere you want.
2929
If you want to use `cargo clif build` instead of having to specify the full path to the `cargo-clif` executable, you can add the `bin` subdirectory of the extracted `dist` directory to your `PATH`.
3030
(tutorial [for Windows](https://stackoverflow.com/a/44272417), and [for Linux/MacOS](https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path/26059#26059)).
3131

32-
[releases]: https://github.com/bjorn3/rustc_codegen_cranelift/releases/tag/dev
32+
[releases]: https://github.com/rust-lang/rustc_codegen_cranelift/releases/tag/dev
3333

3434
## Usage
3535

@@ -78,7 +78,7 @@ configuration options.
7878

7979
* Inline assembly ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1041))
8080
* On UNIX there is support for invoking an external assembler for `global_asm!` and `asm!`.
81-
* SIMD ([tracked here](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171), `std::simd` fully works, `std::arch` is partially supported)
81+
* SIMD ([tracked here](https://github.com/rust-lang/rustc_codegen_cranelift/issues/171), `std::simd` fully works, `std::arch` is partially supported)
8282
* Unwinding on panics ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1677), `-Cpanic=abort` is enabled by default)
8383

8484
## License

Diff for: example/mini_core_hello_world.rs

+11
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,17 @@ fn main() {
353353

354354
let f = V([0.0, 1.0]);
355355
let _a = f.0[0];
356+
357+
stack_val_align();
358+
}
359+
360+
#[inline(never)]
361+
fn stack_val_align() {
362+
#[repr(align(8192))]
363+
struct Foo(u8);
364+
365+
let a = Foo(0);
366+
assert_eq!(&a as *const Foo as usize % 8192, 0);
356367
}
357368

358369
#[cfg(all(

Diff for: patches/0001-regex-Ignore-test-which-gets-miscompiled-with-llvm-sysroot.patch

-25
This file was deleted.

Diff for: src/abi/mod.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,25 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
120120
args: &[Value],
121121
) -> Cow<'_, [Value]> {
122122
if self.tcx.sess.target.is_like_windows {
123-
let (mut params, mut args): (Vec<_>, Vec<_>) =
124-
params
125-
.into_iter()
126-
.zip(args)
127-
.map(|(param, &arg)| {
128-
if param.value_type == types::I128 {
129-
let arg_ptr = Pointer::stack_slot(self.bcx.create_sized_stack_slot(
130-
StackSlotData { kind: StackSlotKind::ExplicitSlot, size: 16 },
131-
));
132-
arg_ptr.store(self, arg, MemFlags::trusted());
133-
(AbiParam::new(self.pointer_type), arg_ptr.get_addr(self))
134-
} else {
135-
(param, arg)
136-
}
137-
})
138-
.unzip();
123+
let (mut params, mut args): (Vec<_>, Vec<_>) = params
124+
.into_iter()
125+
.zip(args)
126+
.map(|(param, &arg)| {
127+
if param.value_type == types::I128 {
128+
let arg_ptr = self.create_stack_slot(16, 16);
129+
arg_ptr.store(self, arg, MemFlags::trusted());
130+
(AbiParam::new(self.pointer_type), arg_ptr.get_addr(self))
131+
} else {
132+
(param, arg)
133+
}
134+
})
135+
.unzip();
139136

140137
let indirect_ret_val = returns.len() == 1 && returns[0].value_type == types::I128;
141138

142139
if indirect_ret_val {
143140
params.insert(0, AbiParam::new(self.pointer_type));
144-
let ret_ptr =
145-
Pointer::stack_slot(self.bcx.create_sized_stack_slot(StackSlotData {
146-
kind: StackSlotKind::ExplicitSlot,
147-
size: 16,
148-
}));
141+
let ret_ptr = self.create_stack_slot(16, 16);
149142
args.insert(0, ret_ptr.get_addr(self));
150143
self.lib_call_unadjusted(name, params, vec![], &args);
151144
return Cow::Owned(vec![ret_ptr.load(self, types::I128, MemFlags::trusted())]);

Diff for: src/abi/pass_mode.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,13 @@ pub(super) fn from_casted_value<'tcx>(
189189
let abi_params = cast_target_to_abi_params(cast);
190190
let abi_param_size: u32 = abi_params.iter().map(|param| param.value_type.bytes()).sum();
191191
let layout_size = u32::try_from(layout.size.bytes()).unwrap();
192-
let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData {
193-
kind: StackSlotKind::ExplicitSlot,
194-
// FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to
195-
// specify stack slot alignment.
192+
let ptr = fx.create_stack_slot(
196193
// Stack slot size may be bigger for example `[u8; 3]` which is packed into an `i32`.
197194
// It may also be smaller for example when the type is a wrapper around an integer with a
198195
// larger alignment than the integer.
199-
size: (std::cmp::max(abi_param_size, layout_size) + 15) / 16 * 16,
200-
});
201-
let ptr = Pointer::stack_slot(stack_slot);
196+
std::cmp::max(abi_param_size, layout_size),
197+
u32::try_from(layout.align.pref.bytes()).unwrap(),
198+
);
202199
let mut offset = 0;
203200
let mut block_params_iter = block_params.iter().copied();
204201
for param in abi_params {

Diff for: src/cast.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ pub(crate) fn clif_int_or_float_cast(
104104
&[from],
105105
)[0];
106106
// FIXME(bytecodealliance/wasmtime#6104) use bitcast instead of store to get from i64x2 to i128
107-
let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData {
108-
kind: StackSlotKind::ExplicitSlot,
109-
size: 16,
110-
});
111-
let ret_ptr = Pointer::stack_slot(stack_slot);
107+
let ret_ptr = fx.create_stack_slot(16, 16);
112108
ret_ptr.store(fx, ret, MemFlags::trusted());
113109
ret_ptr.load(fx, types::I128, MemFlags::trusted())
114110
} else {

Diff for: src/common.rs

+19
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,25 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
383383
})
384384
}
385385

386+
pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
387+
if align <= 16 {
388+
let stack_slot = self.bcx.create_sized_stack_slot(StackSlotData {
389+
kind: StackSlotKind::ExplicitSlot,
390+
// FIXME Don't force the size to a multiple of 16 bytes once Cranelift gets a way to
391+
// specify stack slot alignment.
392+
size: (size + 15) / 16 * 16,
393+
});
394+
Pointer::stack_slot(stack_slot)
395+
} else {
396+
// Alignment is too big to handle using the above hack. Dynamically realign a stack slot
397+
// instead. This wastes some space for the realignment.
398+
let base_ptr = self.create_stack_slot(size + align, 16).get_addr(self);
399+
let misalign_offset = self.bcx.ins().urem_imm(base_ptr, i64::from(align));
400+
let realign_offset = self.bcx.ins().irsub_imm(misalign_offset, i64::from(align));
401+
Pointer::new(self.bcx.ins().iadd(base_ptr, realign_offset))
402+
}
403+
}
404+
386405
pub(crate) fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
387406
if let Some(debug_context) = &mut self.cx.debug_context {
388407
let (file, line, column) =

Diff for: src/driver/aot.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,26 @@ pub(crate) fn run_aot(
361361
metadata: EncodedMetadata,
362362
need_metadata_module: bool,
363363
) -> Box<OngoingCodegen> {
364+
// FIXME handle `-Ctarget-cpu=native`
365+
let target_cpu = match tcx.sess.opts.cg.target_cpu {
366+
Some(ref name) => name,
367+
None => tcx.sess.target.cpu.as_ref(),
368+
}
369+
.to_owned();
370+
364371
let cgus = if tcx.sess.opts.output_types.should_codegen() {
365372
tcx.collect_and_partition_mono_items(()).1
366373
} else {
367374
// If only `--emit metadata` is used, we shouldn't perform any codegen.
368375
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
369-
&[]
376+
return Box::new(OngoingCodegen {
377+
modules: vec![],
378+
allocator_module: None,
379+
metadata_module: None,
380+
metadata,
381+
crate_info: CrateInfo::new(tcx, target_cpu),
382+
concurrency_limiter: ConcurrencyLimiter::new(tcx.sess, 0),
383+
});
370384
};
371385

372386
if tcx.dep_graph.is_fully_enabled() {
@@ -481,13 +495,6 @@ pub(crate) fn run_aot(
481495
None
482496
};
483497

484-
// FIXME handle `-Ctarget-cpu=native`
485-
let target_cpu = match tcx.sess.opts.cg.target_cpu {
486-
Some(ref name) => name,
487-
None => tcx.sess.target.cpu.as_ref(),
488-
}
489-
.to_owned();
490-
491498
Box::new(OngoingCodegen {
492499
modules,
493500
allocator_module,

0 commit comments

Comments
 (0)