Skip to content

Commit

Permalink
Update to cranelift 0.91
Browse files Browse the repository at this point in the history
Closes #1307
  • Loading branch information
bjorn3 committed Dec 22, 2022
1 parent 8b47801 commit debd45c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 54 deletions.
94 changes: 54 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ crate-type = ["dylib"]

[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.90.1", features = ["unwind", "all-arch"] }
cranelift-frontend = "0.90.1"
cranelift-module = "0.90.1"
cranelift-native = "0.90.1"
cranelift-jit = { version = "0.90.1", optional = true }
cranelift-object = "0.90.1"
cranelift-codegen = { version = "0.91", features = ["unwind", "all-arch"] }
cranelift-frontend = "0.91"
cranelift-module = "0.91"
cranelift-native = "0.91"
cranelift-jit = { version = "0.91", optional = true }
cranelift-object = "0.91"
target-lexicon = "0.12.0"
gimli = { version = "0.26.0", default-features = false, features = ["write"]}
object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
Expand Down
5 changes: 2 additions & 3 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub(crate) fn codegen_fn<'tcx>(
};

tcx.sess.time("codegen clif ir", || codegen_fn_body(&mut fx, start_block));
fx.bcx.seal_all_blocks();
fx.bcx.finalize();

// Recover all necessary data from fx, before accessing func will prevent future access to it.
let symbol_name = fx.symbol_name;
Expand Down Expand Up @@ -487,9 +489,6 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
}
};
}

fx.bcx.seal_all_blocks();
fx.bcx.finalize();
}

fn codegen_stmt<'tcx>(
Expand Down
9 changes: 9 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ pub(crate) fn codegen_icmp_imm(
}
}

pub(crate) fn codegen_bitcast(fx: &mut FunctionCx<'_, '_, '_>, dst_ty: Type, val: Value) -> Value {
let mut flags = MemFlags::new();
flags.set_endianness(match fx.tcx.data_layout.endian {
rustc_target::abi::Endian::Big => cranelift_codegen::ir::Endianness::Big,
rustc_target::abi::Endian::Little => cranelift_codegen::ir::Endianness::Little,
});
fx.bcx.ins().bitcast(dst_ty, flags, val)
}

pub(crate) fn type_zero_value(bcx: &mut FunctionBuilder<'_>, ty: Type) -> Value {
if ty == types::I128 {
let zero = bcx.ins().iconst(types::I64, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/intrinsics/llvm_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(

// cast float to int
let a_lane = match lane_ty {
types::F32 => fx.bcx.ins().bitcast(types::I32, a_lane),
types::F64 => fx.bcx.ins().bitcast(types::I64, a_lane),
types::F32 => codegen_bitcast(fx, types::I32, a_lane),
types::F64 => codegen_bitcast(fx, types::I64, a_lane),
_ => a_lane,
};

Expand Down
2 changes: 1 addition & 1 deletion src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn bool_to_zero_or_max_uint<'tcx>(
let mut res = fx.bcx.ins().bmask(int_ty, val);

if ty.is_float() {
res = fx.bcx.ins().bitcast(ty, res);
res = codegen_bitcast(fx, ty, res);
}

res
Expand Down
4 changes: 2 additions & 2 deletions src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ impl<'tcx> CPlace<'tcx> {
(types::I32, types::F32)
| (types::F32, types::I32)
| (types::I64, types::F64)
| (types::F64, types::I64) => fx.bcx.ins().bitcast(dst_ty, data),
_ if src_ty.is_vector() && dst_ty.is_vector() => fx.bcx.ins().bitcast(dst_ty, data),
| (types::F64, types::I64) => codegen_bitcast(fx, dst_ty, data),
_ if src_ty.is_vector() && dst_ty.is_vector() => codegen_bitcast(fx, dst_ty, data),
_ if src_ty.is_vector() || dst_ty.is_vector() => {
// FIXME do something more efficient for transmutes between vectors and integers.
let stack_slot = fx.bcx.create_sized_stack_slot(StackSlotData {
Expand Down

0 comments on commit debd45c

Please sign in to comment.