1
Fork 0

Change ty.kind to a method

This commit is contained in:
LeSeulArtichaut 2020-08-03 00:49:11 +02:00
parent ef55a0a92f
commit 3e14b684dd
189 changed files with 947 additions and 899 deletions

View file

@ -90,7 +90,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let tcx = self.tcx;
let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
let (def_id, substs) = match callee_ty.kind {
let (def_id, substs) = match *callee_ty.kind() {
ty::FnDef(def_id, substs) => (def_id, substs),
_ => bug!("expected fn item type, found {}", callee_ty),
};
@ -1271,7 +1271,7 @@ fn generic_simd_intrinsic(
if name == sym::simd_select_bitmask {
let in_ty = arg_tys[0];
let m_len = match in_ty.kind {
let m_len = match in_ty.kind() {
// Note that this `.unwrap()` crashes for isize/usize, that's sort
// of intentional as there's not currently a use case for that.
ty::Int(i) => i.bit_width().unwrap(),
@ -1436,7 +1436,7 @@ fn generic_simd_intrinsic(
m_len,
v_len
);
match m_elem_ty.kind {
match m_elem_ty.kind() {
ty::Int(_) => {}
_ => return_error!("mask element type is `{}`, expected `i_`", m_elem_ty),
}
@ -1455,13 +1455,13 @@ fn generic_simd_intrinsic(
// If the vector has less than 8 lanes, an u8 is returned with zeroed
// trailing bits.
let expected_int_bits = in_len.max(8);
match ret_ty.kind {
match ret_ty.kind() {
ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => (),
_ => return_error!("bitmask `{}`, expected `u{}`", ret_ty, expected_int_bits),
}
// Integer vector <i{in_bitwidth} x in_len>:
let (i_xn, in_elem_bitwidth) = match in_elem.kind {
let (i_xn, in_elem_bitwidth) = match in_elem.kind() {
ty::Int(i) => {
(args[0].immediate(), i.bit_width().unwrap_or(bx.data_layout().pointer_size.bits()))
}
@ -1518,7 +1518,7 @@ fn generic_simd_intrinsic(
}
}
}
let ety = match in_elem.kind {
let ety = match in_elem.kind() {
ty::Float(f) if f.bit_width() == 32 => {
if in_len < 2 || in_len > 16 {
return_error!(
@ -1612,7 +1612,7 @@ fn generic_simd_intrinsic(
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
fn llvm_vector_str(elem_ty: Ty<'_>, vec_len: u64, no_pointers: usize) -> String {
let p0s: String = "p0".repeat(no_pointers);
match elem_ty.kind {
match *elem_ty.kind() {
ty::Int(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
ty::Uint(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
ty::Float(v) => format!("v{}{}f{}", vec_len, p0s, v.bit_width()),
@ -1627,7 +1627,7 @@ fn generic_simd_intrinsic(
mut no_pointers: usize,
) -> &'ll Type {
// FIXME: use cx.layout_of(ty).llvm_type() ?
let mut elem_ty = match elem_ty.kind {
let mut elem_ty = match *elem_ty.kind() {
ty::Int(v) => cx.type_int_from_ty(v),
ty::Uint(v) => cx.type_uint_from_ty(v),
ty::Float(v) => cx.type_float_from_ty(v),
@ -1680,7 +1680,7 @@ fn generic_simd_intrinsic(
// This counts how many pointers
fn ptr_count(t: Ty<'_>) -> usize {
match t.kind {
match t.kind() {
ty::RawPtr(p) => 1 + ptr_count(p.ty),
_ => 0,
}
@ -1688,7 +1688,7 @@ fn generic_simd_intrinsic(
// Non-ptr type
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
match t.kind {
match t.kind() {
ty::RawPtr(p) => non_ptr(p.ty),
_ => t,
}
@ -1696,7 +1696,7 @@ fn generic_simd_intrinsic(
// The second argument must be a simd vector with an element type that's a pointer
// to the element type of the first argument
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind {
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind() {
ty::RawPtr(p) if p.ty == in_elem => {
(ptr_count(arg_tys[1].simd_type(tcx)), non_ptr(arg_tys[1].simd_type(tcx)))
}
@ -1721,7 +1721,7 @@ fn generic_simd_intrinsic(
assert_eq!(underlying_ty, non_ptr(arg_tys[0].simd_type(tcx)));
// The element type of the third argument must be a signed integer type of any width:
match arg_tys[2].simd_type(tcx).kind {
match arg_tys[2].simd_type(tcx).kind() {
ty::Int(_) => (),
_ => {
require!(
@ -1803,7 +1803,7 @@ fn generic_simd_intrinsic(
// This counts how many pointers
fn ptr_count(t: Ty<'_>) -> usize {
match t.kind {
match t.kind() {
ty::RawPtr(p) => 1 + ptr_count(p.ty),
_ => 0,
}
@ -1811,7 +1811,7 @@ fn generic_simd_intrinsic(
// Non-ptr type
fn non_ptr(t: Ty<'_>) -> Ty<'_> {
match t.kind {
match t.kind() {
ty::RawPtr(p) => non_ptr(p.ty),
_ => t,
}
@ -1819,7 +1819,7 @@ fn generic_simd_intrinsic(
// The second argument must be a simd vector with an element type that's a pointer
// to the element type of the first argument
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind {
let (pointer_count, underlying_ty) = match arg_tys[1].simd_type(tcx).kind() {
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
(ptr_count(arg_tys[1].simd_type(tcx)), non_ptr(arg_tys[1].simd_type(tcx)))
}
@ -1844,7 +1844,7 @@ fn generic_simd_intrinsic(
assert_eq!(underlying_ty, non_ptr(arg_tys[0].simd_type(tcx)));
// The element type of the third argument must be a signed integer type of any width:
match arg_tys[2].simd_type(tcx).kind {
match arg_tys[2].simd_type(tcx).kind() {
ty::Int(_) => (),
_ => {
require!(
@ -1900,7 +1900,7 @@ fn generic_simd_intrinsic(
in_ty,
ret_ty
);
return match in_elem.kind {
return match in_elem.kind() {
ty::Int(_) | ty::Uint(_) => {
let r = bx.$integer_reduce(args[0].immediate());
if $ordered {
@ -1972,7 +1972,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
in_ty,
ret_ty
);
return match in_elem.kind {
return match in_elem.kind() {
ty::Int(_i) => Ok(bx.$int_red(args[0].immediate(), true)),
ty::Uint(_u) => Ok(bx.$int_red(args[0].immediate(), false)),
ty::Float(_f) => Ok(bx.$float_red(args[0].immediate())),
@ -2007,7 +2007,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
);
args[0].immediate()
} else {
match in_elem.kind {
match in_elem.kind() {
ty::Int(_) | ty::Uint(_) => {}
_ => return_error!(
"unsupported {} from `{}` with element `{}` to `{}`",
@ -2023,7 +2023,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
let i1xn = bx.type_vector(i1, in_len as u64);
bx.trunc(args[0].immediate(), i1xn)
};
return match in_elem.kind {
return match in_elem.kind() {
ty::Int(_) | ty::Uint(_) => {
let r = bx.$red(input);
Ok(if !$boolean { r } else { bx.zext(r, bx.type_bool()) })
@ -2071,7 +2071,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
Unsupported,
}
let (in_style, in_width) = match in_elem.kind {
let (in_style, in_width) = match in_elem.kind() {
// vectors of pointer-sized integers should've been
// disallowed before here, so this unwrap is safe.
ty::Int(i) => (Style::Int(true), i.bit_width().unwrap()),
@ -2079,7 +2079,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
ty::Float(f) => (Style::Float, f.bit_width()),
_ => (Style::Unsupported, 0),
};
let (out_style, out_width) = match out_elem.kind {
let (out_style, out_width) = match out_elem.kind() {
ty::Int(i) => (Style::Int(true), i.bit_width().unwrap()),
ty::Uint(u) => (Style::Int(false), u.bit_width().unwrap()),
ty::Float(f) => (Style::Float, f.bit_width()),
@ -2135,7 +2135,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
macro_rules! arith {
($($name: ident: $($($p: ident),* => $call: ident),*;)*) => {
$(if name == sym::$name {
match in_elem.kind {
match in_elem.kind() {
$($(ty::$p(_))|* => {
return Ok(bx.$call(args[0].immediate(), args[1].immediate()))
})*
@ -2169,7 +2169,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
let rhs = args[1].immediate();
let is_add = name == sym::simd_saturating_add;
let ptr_bits = bx.tcx().data_layout.pointer_size.bits() as _;
let (signed, elem_width, elem_ty) = match in_elem.kind {
let (signed, elem_width, elem_ty) = match *in_elem.kind() {
ty::Int(i) => (true, i.bit_width().unwrap_or(ptr_bits), bx.cx.type_int_from_ty(i)),
ty::Uint(i) => (false, i.bit_width().unwrap_or(ptr_bits), bx.cx.type_uint_from_ty(i)),
_ => {
@ -2204,7 +2204,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
// FIXME: theres multiple of this functions, investigate using some of the already existing
// stuffs.
fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
match ty.kind {
match ty.kind() {
ty::Int(t) => Some((
match t {
ast::IntTy::Isize => u64::from(cx.tcx.sess.target.ptr_width),
@ -2234,7 +2234,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
// Returns the width of a float Ty
// Returns None if the type is not a float
fn float_type_width(ty: Ty<'_>) -> Option<u64> {
match ty.kind {
match ty.kind() {
ty::Float(t) => Some(t.bit_width()),
_ => None,
}