Skip to content

Commit 0ed4495

Browse files
committed
Generate LLVM SIMD vector types
1 parent 784e836 commit 0ed4495

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

src/librustc/middle/trans/type_of.rs

+28-15
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,15 @@ pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
155155
}
156156

157157
ty::ty_struct(did, _) => {
158-
let repr = adt::represent_type(cx, t);
159-
let packed = ty::lookup_packed(cx.tcx, did);
160-
T_struct(adt::sizing_fields_of(cx, repr), packed)
158+
if ty::type_is_simd(cx.tcx, t) {
159+
let et = ty::simd_type(cx.tcx, t);
160+
let n = ty::simd_size(cx.tcx, t);
161+
T_vector(type_of(cx, et), n)
162+
} else {
163+
let repr = adt::represent_type(cx, t);
164+
let packed = ty::lookup_packed(cx.tcx, did);
165+
T_struct(adt::sizing_fields_of(cx, repr), packed)
166+
}
161167
}
162168

163169
ty::ty_self(_) | ty::ty_infer(*) | ty::ty_param(*) | ty::ty_err(*) => {
@@ -263,14 +269,19 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
263269
}
264270
ty::ty_opaque_closure_ptr(_) => T_opaque_box_ptr(cx),
265271
ty::ty_struct(did, ref substs) => {
266-
// Only create the named struct, but don't fill it in. We fill it
267-
// in *after* placing it into the type cache. This prevents
268-
// infinite recursion with recursive struct types.
269-
270-
common::T_named_struct(llvm_type_name(cx,
271-
a_struct,
272-
did,
273-
/*bad*/ copy substs.tps))
272+
if ty::type_is_simd(cx.tcx, t) {
273+
let et = ty::simd_type(cx.tcx, t);
274+
let n = ty::simd_size(cx.tcx, t);
275+
T_vector(type_of(cx, et), n)
276+
} else {
277+
// Only create the named struct, but don't fill it in. We fill it
278+
// in *after* placing it into the type cache. This prevents
279+
// infinite recursion with recursive struct types.
280+
T_named_struct(llvm_type_name(cx,
281+
a_struct,
282+
did,
283+
/*bad*/ copy substs.tps))
284+
}
274285
}
275286
ty::ty_self(*) => cx.tcx.sess.unimpl(~"type_of: ty_self"),
276287
ty::ty_infer(*) => cx.tcx.sess.bug(~"type_of with ty_infer"),
@@ -289,10 +300,12 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
289300
}
290301

291302
ty::ty_struct(did, _) => {
292-
let repr = adt::represent_type(cx, t);
293-
let packed = ty::lookup_packed(cx.tcx, did);
294-
common::set_struct_body(llty, adt::fields_of(cx, repr),
295-
packed);
303+
if !ty::type_is_simd(cx.tcx, t) {
304+
let repr = adt::represent_type(cx, t);
305+
let packed = ty::lookup_packed(cx.tcx, did);
306+
common::set_struct_body(llty, adt::fields_of(cx, repr),
307+
packed);
308+
}
296309
}
297310
_ => ()
298311
}

src/librustc/middle/ty.rs

+27
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,13 @@ pub fn type_is_sequence(ty: t) -> bool {
15671567
}
15681568
}
15691569

1570+
pub fn type_is_simd(cx: ctxt, ty: t) -> bool {
1571+
match get(ty).sty {
1572+
ty_struct(did, _) => lookup_simd(cx, did),
1573+
_ => false
1574+
}
1575+
}
1576+
15701577
pub fn type_is_str(ty: t) -> bool {
15711578
match get(ty).sty {
15721579
ty_estr(_) => true,
@@ -1583,6 +1590,26 @@ pub fn sequence_element_type(cx: ctxt, ty: t) -> t {
15831590
}
15841591
}
15851592

1593+
pub fn simd_type(cx: ctxt, ty: t) -> t {
1594+
match get(ty).sty {
1595+
ty_struct(did, ref substs) => {
1596+
let fields = lookup_struct_fields(cx, did);
1597+
lookup_field_type(cx, did, fields[0].id, substs)
1598+
}
1599+
_ => fail!(~"simd_type called on invalid type")
1600+
}
1601+
}
1602+
1603+
pub fn simd_size(cx: ctxt, ty: t) -> uint {
1604+
match get(ty).sty {
1605+
ty_struct(did, _) => {
1606+
let fields = lookup_struct_fields(cx, did);
1607+
fields.len()
1608+
}
1609+
_ => fail!(~"simd_size called on invalid type")
1610+
}
1611+
}
1612+
15861613
pub fn get_element_type(ty: t, i: uint) -> t {
15871614
match get(ty).sty {
15881615
ty_tup(ref ts) => return ts[i],

0 commit comments

Comments
 (0)