Skip to content

Commit 89c4e37

Browse files
committed
auto merge of #21233 : huonw/rust/simd-size, r=Aatch
This stops the compiler ICEing on the use of SIMD types in FFI signatures. It emits correct code for LLVM intrinsics, but I am quite unsure about the ABI handling in general so I've added a new feature gate `simd_ffi` to try to ensure people don't use it without realising there's a non-trivial risk of codegen brokenness. Closes #20043.
2 parents 3e6eaeb + c8e0e95 commit 89c4e37

File tree

13 files changed

+359
-114
lines changed

13 files changed

+359
-114
lines changed

src/librustc_llvm/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub enum RealPredicate {
304304

305305
// The LLVM TypeKind type - must stay in sync with the def of
306306
// LLVMTypeKind in llvm/include/llvm-c/Core.h
307-
#[derive(Copy, PartialEq)]
307+
#[derive(Copy, PartialEq, Show)]
308308
#[repr(C)]
309309
pub enum TypeKind {
310310
Void = 0,

src/librustc_trans/trans/base.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -835,26 +835,24 @@ pub fn cast_shift_rhs<F, G>(op: ast::BinOp,
835835
G: FnOnce(ValueRef, Type) -> ValueRef,
836836
{
837837
// Shifts may have any size int on the rhs
838-
unsafe {
839-
if ast_util::is_shift_binop(op) {
840-
let mut rhs_llty = val_ty(rhs);
841-
let mut lhs_llty = val_ty(lhs);
842-
if rhs_llty.kind() == Vector { rhs_llty = rhs_llty.element_type() }
843-
if lhs_llty.kind() == Vector { lhs_llty = lhs_llty.element_type() }
844-
let rhs_sz = llvm::LLVMGetIntTypeWidth(rhs_llty.to_ref());
845-
let lhs_sz = llvm::LLVMGetIntTypeWidth(lhs_llty.to_ref());
846-
if lhs_sz < rhs_sz {
847-
trunc(rhs, lhs_llty)
848-
} else if lhs_sz > rhs_sz {
849-
// FIXME (#1877: If shifting by negative
850-
// values becomes not undefined then this is wrong.
851-
zext(rhs, lhs_llty)
852-
} else {
853-
rhs
854-
}
838+
if ast_util::is_shift_binop(op) {
839+
let mut rhs_llty = val_ty(rhs);
840+
let mut lhs_llty = val_ty(lhs);
841+
if rhs_llty.kind() == Vector { rhs_llty = rhs_llty.element_type() }
842+
if lhs_llty.kind() == Vector { lhs_llty = lhs_llty.element_type() }
843+
let rhs_sz = rhs_llty.int_width();
844+
let lhs_sz = lhs_llty.int_width();
845+
if lhs_sz < rhs_sz {
846+
trunc(rhs, lhs_llty)
847+
} else if lhs_sz > rhs_sz {
848+
// FIXME (#1877: If shifting by negative
849+
// values becomes not undefined then this is wrong.
850+
zext(rhs, lhs_llty)
855851
} else {
856852
rhs
857853
}
854+
} else {
855+
rhs
858856
}
859857
}
860858

src/librustc_trans/trans/cabi_aarch64.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
#![allow(non_upper_case_globals)]
1212

13-
use llvm;
14-
use llvm::{Integer, Pointer, Float, Double, Struct, Array};
13+
use llvm::{Integer, Pointer, Float, Double, Struct, Array, Vector};
1514
use llvm::{StructRetAttribute, ZExtAttribute};
1615
use trans::cabi::{FnType, ArgType};
1716
use trans::context::CrateContext;
@@ -30,11 +29,7 @@ fn align(off: uint, ty: Type) -> uint {
3029

3130
fn ty_align(ty: Type) -> uint {
3231
match ty.kind() {
33-
Integer => {
34-
unsafe {
35-
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
36-
}
37-
}
32+
Integer => ((ty.int_width() as uint) + 7) / 8,
3833
Pointer => 8,
3934
Float => 4,
4035
Double => 8,
@@ -50,17 +45,18 @@ fn ty_align(ty: Type) -> uint {
5045
let elt = ty.element_type();
5146
ty_align(elt)
5247
}
48+
Vector => {
49+
let len = ty.vector_length();
50+
let elt = ty.element_type();
51+
ty_align(elt) * len
52+
}
5353
_ => panic!("ty_align: unhandled type")
5454
}
5555
}
5656

5757
fn ty_size(ty: Type) -> uint {
5858
match ty.kind() {
59-
Integer => {
60-
unsafe {
61-
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
62-
}
63-
}
59+
Integer => ((ty.int_width() as uint) + 7) / 8,
6460
Pointer => 8,
6561
Float => 4,
6662
Double => 8,
@@ -80,6 +76,12 @@ fn ty_size(ty: Type) -> uint {
8076
let eltsz = ty_size(elt);
8177
len * eltsz
8278
}
79+
Vector => {
80+
let len = ty.vector_length();
81+
let elt = ty.element_type();
82+
let eltsz = ty_size(elt);
83+
len * eltsz
84+
}
8385
_ => panic!("ty_size: unhandled type")
8486
}
8587
}
@@ -137,7 +139,8 @@ fn is_reg_ty(ty: Type) -> bool {
137139
Integer
138140
| Pointer
139141
| Float
140-
| Double => true,
142+
| Double
143+
| Vector => true,
141144
_ => false
142145
}
143146
}

src/librustc_trans/trans/cabi_arm.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
#![allow(non_upper_case_globals)]
1212

13-
use llvm;
14-
use llvm::{Integer, Pointer, Float, Double, Struct, Array};
13+
use llvm::{Integer, Pointer, Float, Double, Struct, Array, Vector};
1514
use llvm::{StructRetAttribute, ZExtAttribute};
1615
use trans::cabi::{FnType, ArgType};
1716
use trans::context::CrateContext;
@@ -37,11 +36,7 @@ fn align(off: uint, ty: Type, align_fn: TyAlignFn) -> uint {
3736

3837
fn general_ty_align(ty: Type) -> uint {
3938
match ty.kind() {
40-
Integer => {
41-
unsafe {
42-
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
43-
}
44-
}
39+
Integer => ((ty.int_width() as uint) + 7) / 8,
4540
Pointer => 4,
4641
Float => 4,
4742
Double => 8,
@@ -57,6 +52,11 @@ fn general_ty_align(ty: Type) -> uint {
5752
let elt = ty.element_type();
5853
general_ty_align(elt)
5954
}
55+
Vector => {
56+
let len = ty.vector_length();
57+
let elt = ty.element_type();
58+
general_ty_align(elt) * len
59+
}
6060
_ => panic!("ty_align: unhandled type")
6161
}
6262
}
@@ -70,11 +70,7 @@ fn general_ty_align(ty: Type) -> uint {
7070
// /iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html
7171
fn ios_ty_align(ty: Type) -> uint {
7272
match ty.kind() {
73-
Integer => {
74-
unsafe {
75-
cmp::min(4, ((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8)
76-
}
77-
}
73+
Integer => cmp::min(4, ((ty.int_width() as uint) + 7) / 8),
7874
Pointer => 4,
7975
Float => 4,
8076
Double => 4,
@@ -90,17 +86,18 @@ fn ios_ty_align(ty: Type) -> uint {
9086
let elt = ty.element_type();
9187
ios_ty_align(elt)
9288
}
89+
Vector => {
90+
let len = ty.vector_length();
91+
let elt = ty.element_type();
92+
ios_ty_align(elt) * len
93+
}
9394
_ => panic!("ty_align: unhandled type")
9495
}
9596
}
9697

9798
fn ty_size(ty: Type, align_fn: TyAlignFn) -> uint {
9899
match ty.kind() {
99-
Integer => {
100-
unsafe {
101-
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
102-
}
103-
}
100+
Integer => ((ty.int_width() as uint) + 7) / 8,
104101
Pointer => 4,
105102
Float => 4,
106103
Double => 8,
@@ -123,6 +120,12 @@ fn ty_size(ty: Type, align_fn: TyAlignFn) -> uint {
123120
let eltsz = ty_size(elt, align_fn);
124121
len * eltsz
125122
}
123+
Vector => {
124+
let len = ty.vector_length();
125+
let elt = ty.element_type();
126+
let eltsz = ty_size(elt, align_fn);
127+
len * eltsz
128+
}
126129
_ => panic!("ty_size: unhandled type")
127130
}
128131
}
@@ -166,7 +169,8 @@ fn is_reg_ty(ty: Type) -> bool {
166169
Integer
167170
| Pointer
168171
| Float
169-
| Double => true,
172+
| Double
173+
| Vector => true,
170174
_ => false
171175
}
172176
}

src/librustc_trans/trans/cabi_mips.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use libc::c_uint;
1414
use std::cmp;
1515
use llvm;
16-
use llvm::{Integer, Pointer, Float, Double, Struct, Array};
16+
use llvm::{Integer, Pointer, Float, Double, Struct, Array, Vector};
1717
use llvm::{StructRetAttribute, ZExtAttribute};
1818
use trans::cabi::{ArgType, FnType};
1919
use trans::context::CrateContext;
@@ -30,11 +30,7 @@ fn align(off: uint, ty: Type) -> uint {
3030

3131
fn ty_align(ty: Type) -> uint {
3232
match ty.kind() {
33-
Integer => {
34-
unsafe {
35-
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
36-
}
37-
}
33+
Integer => ((ty.int_width() as uint) + 7) / 8,
3834
Pointer => 4,
3935
Float => 4,
4036
Double => 8,
@@ -50,17 +46,18 @@ fn ty_align(ty: Type) -> uint {
5046
let elt = ty.element_type();
5147
ty_align(elt)
5248
}
53-
_ => panic!("ty_size: unhandled type")
49+
Vector => {
50+
let len = ty.vector_length();
51+
let elt = ty.element_type();
52+
ty_align(elt) * len
53+
}
54+
_ => panic!("ty_align: unhandled type")
5455
}
5556
}
5657

5758
fn ty_size(ty: Type) -> uint {
5859
match ty.kind() {
59-
Integer => {
60-
unsafe {
61-
((llvm::LLVMGetIntTypeWidth(ty.to_ref()) as uint) + 7) / 8
62-
}
63-
}
60+
Integer => ((ty.int_width() as uint) + 7) / 8,
6461
Pointer => 4,
6562
Float => 4,
6663
Double => 8,
@@ -80,6 +77,12 @@ fn ty_size(ty: Type) -> uint {
8077
let eltsz = ty_size(elt);
8178
len * eltsz
8279
}
80+
Vector => {
81+
let len = ty.vector_length();
82+
let elt = ty.element_type();
83+
let eltsz = ty_size(elt);
84+
len * eltsz
85+
}
8386
_ => panic!("ty_size: unhandled type")
8487
}
8588
}
@@ -120,7 +123,8 @@ fn is_reg_ty(ty: Type) -> bool {
120123
Integer
121124
| Pointer
122125
| Float
123-
| Double => true,
126+
| Double
127+
| Vector => true,
124128
_ => false
125129
};
126130
}

0 commit comments

Comments
 (0)