Skip to content
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

Sync rustc_codegen_cranelift #87816

Merged
merged 60 commits into from
Aug 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
135edbf
Move LinkerInfo into CrateInfo
bjorn3 Jul 6, 2021
4cfa1fc
Don't pass local_crate_name to link_binary separately
bjorn3 Jul 6, 2021
fb92375
Merge commit '3a31c6d8272c14388a34622193baf553636fe470' into sync_cg_…
bjorn3 Jul 7, 2021
7167f4c
Sync from rust 0deb536ff987d7200f5ea35634781e9df9d5b666
bjorn3 Jul 8, 2021
ab4da11
Rustup to rustc 1.55.0-nightly (d2b04f075 2021-07-07)
bjorn3 Jul 8, 2021
ea8d9ae
Implement the raw_eq intrinsic in codegen_cranelift
scottmcm May 31, 2021
7a0574d
PR Feedback: Don't put SSA-only types in `CValue`s
scottmcm May 31, 2021
e3091d7
Use cranelift's `Type::int` instead of doing the match myself
scottmcm Jun 1, 2021
e7a4323
Remove explicit branch="main" form Cargo.toml
bjorn3 Jul 13, 2021
e643b8b
fix cranelift
RalfJung Jul 12, 2021
b47198a
Consider all fields when comparing DllImports, to remove nondetermini…
ricobbe Jul 12, 2021
17eaf43
Update Cranelift
bjorn3 Jul 17, 2021
f7cfb9d
Remove shl/shr special handling for 128bit ints
bjorn3 Jul 5, 2021
6dc386e
Don't truncate the shift amount
bjorn3 Jul 5, 2021
ede41d1
[CI] Update package list before installing packages
bjorn3 Jul 17, 2021
60340d4
Don't panic when the target is not supported by Cranelift
bjorn3 Jul 17, 2021
80b9e36
Put all cg_clif specific options behind -Zunstable-features
bjorn3 Jul 17, 2021
c2a9839
Disable jit and inline-asm when building as part of rustc
bjorn3 Jul 17, 2021
bd2f72f
Merge pull request #1187 from bjorn3/feature_gating
bjorn3 Jul 17, 2021
d7c3c45
Rollup merge of #87092 - ricobbe:fix-raw-dylib-multiple-definitions, …
JohnTitor Jul 18, 2021
c151bb4
Sync from rust 8df945c4717ffaf923b57bf30c473df6fc98bc85
bjorn3 Jul 19, 2021
0ebb483
Rustup to rustc 1.55.0-nightly (59216858a 2021-07-18)
bjorn3 Jul 19, 2021
3563608
Avoid call to pointer_ty
bjorn3 Jul 19, 2021
c42be79
Support repr(simd) on ADTs containing a single array field
bjorn3 Jul 23, 2021
a7b06e8
Fix two type mismatch bugs
bjorn3 Jul 23, 2021
344cbac
Fix simd_reduce_* intrinsics
bjorn3 Jul 24, 2021
90e4493
Implement more simd intrinsics
bjorn3 Jul 24, 2021
6d2221d
Fix simd_round implementation
bjorn3 Jul 25, 2021
a0fb0fa
Run stdsimd test suite
bjorn3 Jul 25, 2021
581e38b
Add fixme
bjorn3 Jul 25, 2021
1f70802
Merge pull request #1189 from bjorn3/stdsimd_fixes
bjorn3 Jul 26, 2021
424a8c3
Implement "default_alloc_error_handler" feature
bjorn3 Jul 26, 2021
02db151
Add stdsimd to .gitignore and clean_all.sh
bjorn3 Jul 26, 2021
050b417
Introduce the CallTarget enum
bjorn3 Jul 26, 2021
83da1e0
Simplify logic around first_arg
bjorn3 Jul 26, 2021
3361e34
Don't return anything from codegen_with_call_return_arg
bjorn3 Jul 26, 2021
405642b
Handle the extra argument for #[track_caller] earlier
bjorn3 Jul 26, 2021
2abc12d
Fix y.rs build --sysroot llvm
bjorn3 Jul 26, 2021
e387ec9
Fix ABI for Indirect arguments
bjorn3 Jul 26, 2021
472f9f9
Update compiler_builtins version in setup_rust_fork.sh
bjorn3 Jul 26, 2021
641e13e
Replace pointer_ty() with fx.pointer_type where possible
bjorn3 Jul 26, 2021
a2b17e4
Enable a working libcore test
bjorn3 Jul 26, 2021
c2464eb
Update Cranelift, gimli and object
bjorn3 Jul 27, 2021
bcf532c
Update dependencies
bjorn3 Jul 27, 2021
f4ba61e
Rustup to rustc 1.56.0-nightly (08095fc1f 2021-07-26)
bjorn3 Jul 27, 2021
8a6ff90
Use __muloti4 instead of __rust_i128_mulo
bjorn3 Jul 28, 2021
2e62516
Remove workarounds for things unimplemented in Cranelift
bjorn3 Jul 28, 2021
bab224d
Remove outdated FIXME
bjorn3 Jul 28, 2021
8704a66
Allow returning PassMode::Cast directly to an ssa var
bjorn3 Jul 28, 2021
b7881bb
Remove CPlace::no_place
bjorn3 Jul 28, 2021
e0b9f3b
Support storing return values in register places for all pass modes
bjorn3 Jul 28, 2021
c6564f8
Fix float min and max operations in presence of NaN
bjorn3 Jul 29, 2021
84961ef
Re-enable a fixed rustc tests
bjorn3 Jul 29, 2021
966e54e
rfc3052: Remove authors field from Cargo manifests
lf- Jul 27, 2021
6f68223
Implement pointer casting.
crlf0710 Jul 31, 2021
0f83ac1
Auto merge of #87515 - crlf0710:trait_upcasting_part2, r=bjorn3
bors Aug 3, 2021
f9c5bbb
change instructions for manually compiling y.rs (#1191)
gheoan Aug 4, 2021
2049137
Sync from rust 2ddb65c32253872c0e7a02e43ec520877900370e
bjorn3 Aug 5, 2021
05677b6
Rustup to rustc 1.56.0-nightly (25b764849 2021-08-04)
bjorn3 Aug 5, 2021
279f486
Merge commit '05677b6bd6c938ed760835d9b1f6514992654ae3' into sync_cg_…
bjorn3 Aug 6, 2021
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
Prev Previous commit
Next Next commit
Remove workarounds for things unimplemented in Cranelift
Many are now implemented, so it is much nicer to directly use the
respective Cranelift instructions
bjorn3 committed Jul 28, 2021
commit 2e62516496b9b47bcf25a03195ba024fd326f162
2 changes: 0 additions & 2 deletions src/base.rs
Original file line number Diff line number Diff line change
@@ -334,8 +334,6 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
crate::optimize::peephole::maybe_unwrap_bool_not(&mut fx.bcx, discr);
let test_zero = if is_inverted { !test_zero } else { test_zero };
let discr = crate::optimize::peephole::maybe_unwrap_bint(&mut fx.bcx, discr);
let discr =
crate::optimize::peephole::make_branchable_value(&mut fx.bcx, discr);
if let Some(taken) = crate::optimize::peephole::maybe_known_branch_taken(
&fx.bcx, discr, test_zero,
) {
19 changes: 0 additions & 19 deletions src/cast.rs
Original file line number Diff line number Diff line change
@@ -14,21 +14,6 @@ pub(crate) fn clif_intcast(
(_, _) if from == to => val,

// extend
(_, types::I128) => {
let lo = if from == types::I64 {
val
} else if signed {
fx.bcx.ins().sextend(types::I64, val)
} else {
fx.bcx.ins().uextend(types::I64, val)
};
let hi = if signed {
fx.bcx.ins().sshr_imm(lo, 63)
} else {
fx.bcx.ins().iconst(types::I64, 0)
};
fx.bcx.ins().iconcat(lo, hi)
}
(_, _) if to.wider_or_equal(from) => {
if signed {
fx.bcx.ins().sextend(to, val)
@@ -38,10 +23,6 @@ pub(crate) fn clif_intcast(
}

// reduce
(types::I128, _) => {
let (lsb, _msb) = fx.bcx.ins().isplit(val);
if to == types::I64 { lsb } else { fx.bcx.ins().ireduce(to, lsb) }
}
(_, _) => fx.bcx.ins().ireduce(to, val),
}
}
2 changes: 1 addition & 1 deletion src/debuginfo/emit.rs
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ impl Writer for WriterRelocate {
let val = match eh_pe.application() {
gimli::DW_EH_PE_absptr => val,
gimli::DW_EH_PE_pcrel => {
// TODO: better handling of sign
// FIXME better handling of sign
let offset = self.len() as u64;
offset.wrapping_sub(val)
}
2 changes: 1 addition & 1 deletion src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ impl<'tcx> DebugContext<'tcx> {
pub(crate) fn new(tcx: TyCtxt<'tcx>, isa: &dyn TargetIsa) -> Self {
let encoding = Encoding {
format: Format::Dwarf32,
// TODO: this should be configurable
// FIXME this should be configurable
// macOS doesn't seem to support DWARF > 3
// 5 version is required for md5 file hash
version: if tcx.sess.target.is_like_osx {
39 changes: 2 additions & 37 deletions src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
@@ -611,9 +611,6 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
let (val, has_overflow) = checked_res.load_scalar_pair(fx);
let clif_ty = fx.clif_type(T).unwrap();

// `select.i8` is not implemented by Cranelift.
let has_overflow = fx.bcx.ins().uextend(types::I32, has_overflow);

let (min, max) = type_min_max_value(&mut fx.bcx, clif_ty, signed);

let val = match (intrinsic, signed) {
@@ -640,21 +637,11 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
};
rotate_left, <T>(v x, v y) {
let layout = fx.layout_of(T);
let y = if fx.bcx.func.dfg.value_type(y) == types::I128 {
fx.bcx.ins().ireduce(types::I64, y)
} else {
y
};
let res = fx.bcx.ins().rotl(x, y);
ret.write_cvalue(fx, CValue::by_val(res, layout));
};
rotate_right, <T>(v x, v y) {
let layout = fx.layout_of(T);
let y = if fx.bcx.func.dfg.value_type(y) == types::I128 {
fx.bcx.ins().ireduce(types::I64, y)
} else {
y
};
let res = fx.bcx.ins().rotr(x, y);
ret.write_cvalue(fx, CValue::by_val(res, layout));
};
@@ -692,35 +679,13 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
};
ctlz | ctlz_nonzero, <T> (v arg) {
// FIXME trap on `ctlz_nonzero` with zero arg.
let res = if T == fx.tcx.types.u128 || T == fx.tcx.types.i128 {
// FIXME verify this algorithm is correct
let (lsb, msb) = fx.bcx.ins().isplit(arg);
let lsb_lz = fx.bcx.ins().clz(lsb);
let msb_lz = fx.bcx.ins().clz(msb);
let msb_is_zero = fx.bcx.ins().icmp_imm(IntCC::Equal, msb, 0);
let lsb_lz_plus_64 = fx.bcx.ins().iadd_imm(lsb_lz, 64);
let res = fx.bcx.ins().select(msb_is_zero, lsb_lz_plus_64, msb_lz);
fx.bcx.ins().uextend(types::I128, res)
} else {
fx.bcx.ins().clz(arg)
};
let res = fx.bcx.ins().clz(arg);
let res = CValue::by_val(res, fx.layout_of(T));
ret.write_cvalue(fx, res);
};
cttz | cttz_nonzero, <T> (v arg) {
// FIXME trap on `cttz_nonzero` with zero arg.
let res = if T == fx.tcx.types.u128 || T == fx.tcx.types.i128 {
// FIXME verify this algorithm is correct
let (lsb, msb) = fx.bcx.ins().isplit(arg);
let lsb_tz = fx.bcx.ins().ctz(lsb);
let msb_tz = fx.bcx.ins().ctz(msb);
let lsb_is_zero = fx.bcx.ins().icmp_imm(IntCC::Equal, lsb, 0);
let msb_tz_plus_64 = fx.bcx.ins().iadd_imm(msb_tz, 64);
let res = fx.bcx.ins().select(lsb_is_zero, msb_tz_plus_64, lsb_tz);
fx.bcx.ins().uextend(types::I128, res)
} else {
fx.bcx.ins().ctz(arg)
};
let res = fx.bcx.ins().ctz(arg);
let res = CValue::by_val(res, fx.layout_of(T));
ret.write_cvalue(fx, res);
};
13 changes: 0 additions & 13 deletions src/num.rs
Original file line number Diff line number Diff line change
@@ -67,19 +67,6 @@ pub(crate) fn codegen_binop<'tcx>(
let lhs = in_lhs.load_scalar(fx);
let rhs = in_rhs.load_scalar(fx);

let (lhs, rhs) = if (bin_op == BinOp::Eq || bin_op == BinOp::Ne)
&& (in_lhs.layout().ty.kind() == fx.tcx.types.i8.kind()
|| in_lhs.layout().ty.kind() == fx.tcx.types.i16.kind())
{
// FIXME(CraneStation/cranelift#896) icmp_imm.i8/i16 with eq/ne for signed ints is implemented wrong.
(
fx.bcx.ins().sextend(types::I32, lhs),
fx.bcx.ins().sextend(types::I32, rhs),
)
} else {
(lhs, rhs)
};

return codegen_compare_bin_op(fx, bin_op, signed, lhs, rhs);
}
_ => {}
41 changes: 1 addition & 40 deletions src/optimize/peephole.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Peephole optimizations that can be performed while creating clif ir.

use cranelift_codegen::ir::{
condcodes::IntCC, types, InstBuilder, InstructionData, Opcode, Value, ValueDef,
};
use cranelift_codegen::ir::{condcodes::IntCC, InstructionData, Opcode, Value, ValueDef};
use cranelift_frontend::FunctionBuilder;

/// If the given value was produced by a `bint` instruction, return it's input, otherwise return the
@@ -37,43 +35,6 @@ pub(crate) fn maybe_unwrap_bool_not(bcx: &mut FunctionBuilder<'_>, arg: Value) -
}
}

pub(crate) fn make_branchable_value(bcx: &mut FunctionBuilder<'_>, arg: Value) -> Value {
if bcx.func.dfg.value_type(arg).is_bool() {
return arg;
}

(|| {
let arg_inst = if let ValueDef::Result(arg_inst, 0) = bcx.func.dfg.value_def(arg) {
arg_inst
} else {
return None;
};

match bcx.func.dfg[arg_inst] {
// This is the lowering of Rvalue::Not
InstructionData::Load { opcode: Opcode::Load, arg: ptr, flags, offset } => {
// Using `load.i8 + uextend.i32` would legalize to `uload8 + ireduce.i8 +
// uextend.i32`. Just `uload8` is much faster.
match bcx.func.dfg.ctrl_typevar(arg_inst) {
types::I8 => Some(bcx.ins().uload8(types::I32, flags, ptr, offset)),
types::I16 => Some(bcx.ins().uload16(types::I32, flags, ptr, offset)),
_ => None,
}
}
_ => None,
}
})()
.unwrap_or_else(|| {
match bcx.func.dfg.value_type(arg) {
types::I8 | types::I16 => {
// WORKAROUND for brz.i8 and brnz.i8 not yet being implemented
bcx.ins().uextend(types::I32, arg)
}
_ => arg,
}
})
}

/// Returns whether the branch is statically known to be taken or `None` if it isn't statically known.
pub(crate) fn maybe_known_branch_taken(
bcx: &FunctionBuilder<'_>,