Skip to content

Commit 045105b

Browse files
committed
remove internal simd_size_and_ty from llvm backend
1 parent 540b5db commit 045105b

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -740,23 +740,6 @@ fn generic_simd_intrinsic(
740740
llret_ty: &'ll Type,
741741
span: Span,
742742
) -> Result<&'ll Value, ()> {
743-
// Given a SIMD vector type `x` return the element type and the number of
744-
// elements in the vector.
745-
fn simd_ty_and_len(bx: &Builder<'a, 'll, 'tcx>, simd_ty: Ty<'tcx>) -> (Ty<'tcx>, u64) {
746-
let ty = if let ty::Adt(_def, _substs) = simd_ty.kind() {
747-
let f0_ty = bx.layout_of(simd_ty).field(bx, 0).ty;
748-
if let ty::Array(element_ty, _) = f0_ty.kind() { element_ty } else { f0_ty }
749-
} else {
750-
bug!("should only be called with a SIMD type")
751-
};
752-
let count = if let abi::Abi::Vector { count, .. } = bx.layout_of(simd_ty).abi {
753-
count
754-
} else {
755-
bug!("should only be called with a SIMD type")
756-
};
757-
(ty, count)
758-
}
759-
760743
// macros for error handling:
761744
macro_rules! emit_error {
762745
($msg: tt) => {
@@ -809,7 +792,7 @@ fn generic_simd_intrinsic(
809792
_ => return_error!("`{}` is not an integral type", in_ty),
810793
};
811794
require_simd!(arg_tys[1], "argument");
812-
let (_, v_len) = simd_ty_and_len(bx, arg_tys[1]);
795+
let (v_len, _) = arg_tys[1].simd_size_and_type(bx.tcx());
813796
require!(
814797
// Allow masks for vectors with fewer than 8 elements to be
815798
// represented with a u8 or i8.
@@ -840,11 +823,11 @@ fn generic_simd_intrinsic(
840823
_ => None,
841824
};
842825

843-
let (in_elem, in_len) = simd_ty_and_len(bx, arg_tys[0]);
826+
let (in_len, in_elem) = arg_tys[0].simd_size_and_type(bx.tcx());
844827
if let Some(cmp_op) = comparison {
845828
require_simd!(ret_ty, "return");
846829

847-
let (out_ty, out_len) = simd_ty_and_len(bx, ret_ty);
830+
let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
848831
require!(
849832
in_len == out_len,
850833
"expected return type with length {} (same as input type `{}`), \
@@ -878,7 +861,7 @@ fn generic_simd_intrinsic(
878861

879862
require_simd!(ret_ty, "return");
880863

881-
let (out_ty, out_len) = simd_ty_and_len(bx, ret_ty);
864+
let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
882865
require!(
883866
out_len == n,
884867
"expected return type of length {}, found `{}` with length {}",
@@ -962,7 +945,7 @@ fn generic_simd_intrinsic(
962945
let m_elem_ty = in_elem;
963946
let m_len = in_len;
964947
require_simd!(arg_tys[1], "argument");
965-
let (_, v_len) = simd_ty_and_len(bx, arg_tys[1]);
948+
let (v_len, _) = arg_tys[1].simd_size_and_type(bx.tcx());
966949
require!(
967950
m_len == v_len,
968951
"mismatched lengths: mask length `{}` != other vector length `{}`",
@@ -1187,8 +1170,8 @@ fn generic_simd_intrinsic(
11871170
require_simd!(ret_ty, "return");
11881171

11891172
// Of the same length:
1190-
let (_, out_len) = simd_ty_and_len(bx, arg_tys[1]);
1191-
let (_, out_len2) = simd_ty_and_len(bx, arg_tys[2]);
1173+
let (out_len, _) = arg_tys[1].simd_size_and_type(bx.tcx());
1174+
let (out_len2, _) = arg_tys[2].simd_size_and_type(bx.tcx());
11921175
require!(
11931176
in_len == out_len,
11941177
"expected {} argument with length {} (same as input type `{}`), \
@@ -1231,8 +1214,8 @@ fn generic_simd_intrinsic(
12311214

12321215
// The second argument must be a simd vector with an element type that's a pointer
12331216
// to the element type of the first argument
1234-
let (element_ty0, _) = simd_ty_and_len(bx, arg_tys[0]);
1235-
let (element_ty1, _) = simd_ty_and_len(bx, arg_tys[1]);
1217+
let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx());
1218+
let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx());
12361219
let (pointer_count, underlying_ty) = match element_ty1.kind() {
12371220
ty::RawPtr(p) if p.ty == in_elem => (ptr_count(element_ty1), non_ptr(element_ty1)),
12381221
_ => {
@@ -1256,7 +1239,7 @@ fn generic_simd_intrinsic(
12561239
assert_eq!(underlying_ty, non_ptr(element_ty0));
12571240

12581241
// The element type of the third argument must be a signed integer type of any width:
1259-
let (element_ty2, _) = simd_ty_and_len(bx, arg_tys[2]);
1242+
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
12601243
match element_ty2.kind() {
12611244
ty::Int(_) => (),
12621245
_ => {
@@ -1316,8 +1299,8 @@ fn generic_simd_intrinsic(
13161299
require_simd!(arg_tys[2], "third");
13171300

13181301
// Of the same length:
1319-
let (_, element_len1) = simd_ty_and_len(bx, arg_tys[1]);
1320-
let (_, element_len2) = simd_ty_and_len(bx, arg_tys[2]);
1302+
let (element_len1, _) = arg_tys[1].simd_size_and_type(bx.tcx());
1303+
let (element_len2, _) = arg_tys[2].simd_size_and_type(bx.tcx());
13211304
require!(
13221305
in_len == element_len1,
13231306
"expected {} argument with length {} (same as input type `{}`), \
@@ -1357,9 +1340,9 @@ fn generic_simd_intrinsic(
13571340

13581341
// The second argument must be a simd vector with an element type that's a pointer
13591342
// to the element type of the first argument
1360-
let (element_ty0, _element_len0) = simd_ty_and_len(bx, arg_tys[0]);
1361-
let (element_ty1, _element_len1) = simd_ty_and_len(bx, arg_tys[1]);
1362-
let (element_ty2, _element_len2) = simd_ty_and_len(bx, arg_tys[2]);
1343+
let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx());
1344+
let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx());
1345+
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
13631346
let (pointer_count, underlying_ty) = match element_ty1.kind() {
13641347
ty::RawPtr(p) if p.ty == in_elem && p.mutbl == hir::Mutability::Mut => {
13651348
(ptr_count(element_ty1), non_ptr(element_ty1))
@@ -1589,7 +1572,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
15891572

15901573
if name == sym::simd_cast {
15911574
require_simd!(ret_ty, "return");
1592-
let (out_elem, out_len) = simd_ty_and_len(bx, ret_ty);
1575+
let (out_len, out_elem) = ret_ty.simd_size_and_type(bx.tcx());
15931576
require!(
15941577
in_len == out_len,
15951578
"expected return type with length {} (same as input type `{}`), \
@@ -1715,7 +1698,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
17151698
return_error!(
17161699
"expected element type `{}` of vector type `{}` \
17171700
to be a signed or unsigned integer type",
1718-
simd_ty_and_len(bx, arg_tys[0]).0,
1701+
arg_tys[0].simd_size_and_type(bx.tcx()).1,
17191702
arg_tys[0]
17201703
);
17211704
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,12 @@ impl<'tcx> TyS<'tcx> {
19631963
match self.kind() {
19641964
Adt(def, substs) => {
19651965
let variant = def.non_enum_variant();
1966-
(variant.fields.len() as u64, variant.fields[0].ty(tcx, substs))
1966+
let f0_ty = variant.fields[0].ty(tcx, substs);
1967+
1968+
match f0_ty.kind() {
1969+
Array(f0_elem_ty, f0_len) => (f0_len.eval_usize(tcx, ParamEnv::empty()) as u64, f0_elem_ty),
1970+
_ => (variant.fields.len() as u64, f0_ty),
1971+
}
19671972
}
19681973
_ => bug!("`simd_size_and_type` called on invalid type"),
19691974
}

0 commit comments

Comments
 (0)