Auto merge of #76071 - khyperia:configurable_to_immediate, r=eddyb
Make to_immediate/from_immediate configurable by backends `librustc_codegen_ssa` has the concept of an immediate vs. memory type, and `librustc_codegen_llvm` uses this distinction to implement `bool`s being `i8` in memory, and `i1` in immediate contexts. However, some of that implementation leaked into `codegen_ssa` when converting to/from immediate values. So, move those methods into builder traits, so that behavior can be configured by backends. This is useful if a backend is able to keep bools as bools, or, needs to do more trickery than just bools to bytes. (Note that there's already a large amount of things abstracted with "immediate types" - this is just bringing this particular thing in line to be abstracted as well) --- Pinging @eddyb since that's who I was talking about this change with when they suggested I submit a PR.
This commit is contained in:
commit
6f1bbf5ee0
7 changed files with 56 additions and 68 deletions
|
@ -38,7 +38,7 @@ use rustc_middle::middle::cstore::EncodedMetadata;
|
|||
use rustc_middle::middle::cstore::{self, LinkagePreference};
|
||||
use rustc_middle::middle::lang_items;
|
||||
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
|
||||
use rustc_middle::ty::layout::{self, HasTyCtxt, TyAndLayout};
|
||||
use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout};
|
||||
use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
||||
|
@ -48,7 +48,7 @@ use rustc_session::utils::NativeLibKind;
|
|||
use rustc_session::Session;
|
||||
use rustc_span::Span;
|
||||
use rustc_symbol_mangling::test as symbol_names_test;
|
||||
use rustc_target::abi::{Abi, Align, LayoutOf, Scalar, VariantIdx};
|
||||
use rustc_target::abi::{Align, LayoutOf, VariantIdx};
|
||||
|
||||
use std::cmp;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
@ -330,35 +330,6 @@ pub fn wants_msvc_seh(sess: &Session) -> bool {
|
|||
sess.target.target.options.is_like_msvc
|
||||
}
|
||||
|
||||
pub fn from_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
val: Bx::Value,
|
||||
) -> Bx::Value {
|
||||
if bx.cx().val_ty(val) == bx.cx().type_i1() { bx.zext(val, bx.cx().type_i8()) } else { val }
|
||||
}
|
||||
|
||||
pub fn to_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
val: Bx::Value,
|
||||
layout: layout::TyAndLayout<'_>,
|
||||
) -> Bx::Value {
|
||||
if let Abi::Scalar(ref scalar) = layout.abi {
|
||||
return to_immediate_scalar(bx, val, scalar);
|
||||
}
|
||||
val
|
||||
}
|
||||
|
||||
pub fn to_immediate_scalar<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
val: Bx::Value,
|
||||
scalar: &Scalar,
|
||||
) -> Bx::Value {
|
||||
if scalar.is_bool() {
|
||||
return bx.trunc(val, bx.cx().type_i1());
|
||||
}
|
||||
val
|
||||
}
|
||||
|
||||
pub fn memcpy_ty<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &mut Bx,
|
||||
dst: Bx::Value,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue