@@ -1307,49 +1307,34 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
1307
1307
// FIXME: use:
1308
1308
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182
1309
1309
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
1310
- fn llvm_vector_str (
1311
- elem_ty : Ty < ' _ > ,
1312
- vec_len : u64 ,
1313
- no_pointers : usize ,
1314
- bx : & Builder < ' _ , ' _ , ' _ > ,
1315
- ) -> String {
1316
- let p0s: String = "p0" . repeat ( no_pointers) ;
1310
+ fn llvm_vector_str ( bx : & Builder < ' _ , ' _ , ' _ > , elem_ty : Ty < ' _ > , vec_len : u64 ) -> String {
1317
1311
match * elem_ty. kind ( ) {
1318
1312
ty:: Int ( v) => format ! (
1319
- "v{}{} i{}" ,
1313
+ "v{}i{}" ,
1320
1314
vec_len,
1321
- p0s,
1322
1315
// Normalize to prevent crash if v: IntTy::Isize
1323
1316
v. normalize( bx. target_spec( ) . pointer_width) . bit_width( ) . unwrap( )
1324
1317
) ,
1325
1318
ty:: Uint ( v) => format ! (
1326
- "v{}{} i{}" ,
1319
+ "v{}i{}" ,
1327
1320
vec_len,
1328
- p0s,
1329
1321
// Normalize to prevent crash if v: UIntTy::Usize
1330
1322
v. normalize( bx. target_spec( ) . pointer_width) . bit_width( ) . unwrap( )
1331
1323
) ,
1332
- ty:: Float ( v) => format ! ( "v{}{}f{}" , vec_len, p0s, v. bit_width( ) ) ,
1324
+ ty:: Float ( v) => format ! ( "v{}f{}" , vec_len, v. bit_width( ) ) ,
1325
+ ty:: RawPtr ( _) => format ! ( "v{}p0" , vec_len) ,
1333
1326
_ => unreachable ! ( ) ,
1334
1327
}
1335
1328
}
1336
1329
1337
- fn llvm_vector_ty < ' ll > (
1338
- cx : & CodegenCx < ' ll , ' _ > ,
1339
- elem_ty : Ty < ' _ > ,
1340
- vec_len : u64 ,
1341
- no_pointers : usize ,
1342
- ) -> & ' ll Type {
1343
- // FIXME: use cx.layout_of(ty).llvm_type() ?
1344
- let mut elem_ty = match * elem_ty. kind ( ) {
1330
+ fn llvm_vector_ty < ' ll > ( cx : & CodegenCx < ' ll , ' _ > , elem_ty : Ty < ' _ > , vec_len : u64 ) -> & ' ll Type {
1331
+ let elem_ty = match * elem_ty. kind ( ) {
1345
1332
ty:: Int ( v) => cx. type_int_from_ty ( v) ,
1346
1333
ty:: Uint ( v) => cx. type_uint_from_ty ( v) ,
1347
1334
ty:: Float ( v) => cx. type_float_from_ty ( v) ,
1335
+ ty:: RawPtr ( _) => cx. type_ptr ( ) ,
1348
1336
_ => unreachable ! ( ) ,
1349
1337
} ;
1350
- if no_pointers > 0 {
1351
- elem_ty = cx. type_ptr ( ) ;
1352
- }
1353
1338
cx. type_vector ( elem_ty, vec_len)
1354
1339
}
1355
1340
@@ -1404,47 +1389,26 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
1404
1389
InvalidMonomorphization :: ExpectedReturnType { span, name, in_ty, ret_ty }
1405
1390
) ;
1406
1391
1407
- // This counts how many pointers
1408
- fn ptr_count ( t : Ty < ' _ > ) -> usize {
1409
- match t. kind ( ) {
1410
- ty:: RawPtr ( p) => 1 + ptr_count ( p. ty ) ,
1411
- _ => 0 ,
1412
- }
1413
- }
1414
-
1415
- // Non-ptr type
1416
- fn non_ptr ( t : Ty < ' _ > ) -> Ty < ' _ > {
1417
- match t. kind ( ) {
1418
- ty:: RawPtr ( p) => non_ptr ( p. ty ) ,
1419
- _ => t,
1420
- }
1421
- }
1422
-
1423
1392
// The second argument must be a simd vector with an element type that's a pointer
1424
1393
// to the element type of the first argument
1425
1394
let ( _, element_ty0) = arg_tys[ 0 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1426
1395
let ( _, element_ty1) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1427
- let ( pointer_count, underlying_ty) = match element_ty1. kind ( ) {
1428
- ty:: RawPtr ( p) if p. ty == in_elem => ( ptr_count ( element_ty1) , non_ptr ( element_ty1) ) ,
1429
- _ => {
1430
- require ! (
1431
- false ,
1432
- InvalidMonomorphization :: ExpectedElementType {
1433
- span,
1434
- name,
1435
- expected_element: element_ty1,
1436
- second_arg: arg_tys[ 1 ] ,
1437
- in_elem,
1438
- in_ty,
1439
- mutability: ExpectedPointerMutability :: Not ,
1440
- }
1441
- ) ;
1442
- unreachable ! ( ) ;
1396
+
1397
+ require ! (
1398
+ matches!(
1399
+ element_ty1. kind( ) ,
1400
+ ty:: RawPtr ( p) if p. ty == in_elem && p. ty. kind( ) == element_ty0. kind( )
1401
+ ) ,
1402
+ InvalidMonomorphization :: ExpectedElementType {
1403
+ span,
1404
+ name,
1405
+ expected_element: element_ty1,
1406
+ second_arg: arg_tys[ 1 ] ,
1407
+ in_elem,
1408
+ in_ty,
1409
+ mutability: ExpectedPointerMutability :: Not ,
1443
1410
}
1444
- } ;
1445
- assert ! ( pointer_count > 0 ) ;
1446
- assert_eq ! ( pointer_count - 1 , ptr_count( element_ty0) ) ;
1447
- assert_eq ! ( underlying_ty, non_ptr( element_ty0) ) ;
1411
+ ) ;
1448
1412
1449
1413
// The element type of the third argument must be a signed integer type of any width:
1450
1414
let ( _, element_ty2) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
@@ -1475,12 +1439,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
1475
1439
} ;
1476
1440
1477
1441
// Type of the vector of pointers:
1478
- let llvm_pointer_vec_ty = llvm_vector_ty ( bx, underlying_ty , in_len, pointer_count ) ;
1479
- let llvm_pointer_vec_str = llvm_vector_str ( underlying_ty , in_len , pointer_count , bx ) ;
1442
+ let llvm_pointer_vec_ty = llvm_vector_ty ( bx, element_ty1 , in_len) ;
1443
+ let llvm_pointer_vec_str = llvm_vector_str ( bx , element_ty1 , in_len ) ;
1480
1444
1481
1445
// Type of the vector of elements:
1482
- let llvm_elem_vec_ty = llvm_vector_ty ( bx, underlying_ty , in_len, pointer_count - 1 ) ;
1483
- let llvm_elem_vec_str = llvm_vector_str ( underlying_ty , in_len , pointer_count - 1 , bx ) ;
1446
+ let llvm_elem_vec_ty = llvm_vector_ty ( bx, element_ty0 , in_len) ;
1447
+ let llvm_elem_vec_str = llvm_vector_str ( bx , element_ty0 , in_len ) ;
1484
1448
1485
1449
let llvm_intrinsic =
1486
1450
format ! ( "llvm.masked.gather.{}.{}" , llvm_elem_vec_str, llvm_pointer_vec_str) ;
@@ -1544,50 +1508,28 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
1544
1508
}
1545
1509
) ;
1546
1510
1547
- // This counts how many pointers
1548
- fn ptr_count ( t : Ty < ' _ > ) -> usize {
1549
- match t. kind ( ) {
1550
- ty:: RawPtr ( p) => 1 + ptr_count ( p. ty ) ,
1551
- _ => 0 ,
1552
- }
1553
- }
1554
-
1555
- // Non-ptr type
1556
- fn non_ptr ( t : Ty < ' _ > ) -> Ty < ' _ > {
1557
- match t. kind ( ) {
1558
- ty:: RawPtr ( p) => non_ptr ( p. ty ) ,
1559
- _ => t,
1560
- }
1561
- }
1562
-
1563
1511
// The second argument must be a simd vector with an element type that's a pointer
1564
1512
// to the element type of the first argument
1565
1513
let ( _, element_ty0) = arg_tys[ 0 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1566
1514
let ( _, element_ty1) = arg_tys[ 1 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1567
1515
let ( _, element_ty2) = arg_tys[ 2 ] . simd_size_and_type ( bx. tcx ( ) ) ;
1568
- let ( pointer_count, underlying_ty) = match element_ty1. kind ( ) {
1569
- ty:: RawPtr ( p) if p. ty == in_elem && p. mutbl . is_mut ( ) => {
1570
- ( ptr_count ( element_ty1) , non_ptr ( element_ty1) )
1571
- }
1572
- _ => {
1573
- require ! (
1574
- false ,
1575
- InvalidMonomorphization :: ExpectedElementType {
1576
- span,
1577
- name,
1578
- expected_element: element_ty1,
1579
- second_arg: arg_tys[ 1 ] ,
1580
- in_elem,
1581
- in_ty,
1582
- mutability: ExpectedPointerMutability :: Mut ,
1583
- }
1584
- ) ;
1585
- unreachable ! ( ) ;
1516
+
1517
+ require ! (
1518
+ matches!(
1519
+ element_ty1. kind( ) ,
1520
+ ty:: RawPtr ( p)
1521
+ if p. ty == in_elem && p. mutbl. is_mut( ) && p. ty. kind( ) == element_ty0. kind( )
1522
+ ) ,
1523
+ InvalidMonomorphization :: ExpectedElementType {
1524
+ span,
1525
+ name,
1526
+ expected_element: element_ty1,
1527
+ second_arg: arg_tys[ 1 ] ,
1528
+ in_elem,
1529
+ in_ty,
1530
+ mutability: ExpectedPointerMutability :: Mut ,
1586
1531
}
1587
- } ;
1588
- assert ! ( pointer_count > 0 ) ;
1589
- assert_eq ! ( pointer_count - 1 , ptr_count( element_ty0) ) ;
1590
- assert_eq ! ( underlying_ty, non_ptr( element_ty0) ) ;
1532
+ ) ;
1591
1533
1592
1534
// The element type of the third argument must be a signed integer type of any width:
1593
1535
match element_ty2. kind ( ) {
@@ -1619,12 +1561,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
1619
1561
let ret_t = bx. type_void ( ) ;
1620
1562
1621
1563
// Type of the vector of pointers:
1622
- let llvm_pointer_vec_ty = llvm_vector_ty ( bx, underlying_ty , in_len, pointer_count ) ;
1623
- let llvm_pointer_vec_str = llvm_vector_str ( underlying_ty , in_len , pointer_count , bx ) ;
1564
+ let llvm_pointer_vec_ty = llvm_vector_ty ( bx, element_ty1 , in_len) ;
1565
+ let llvm_pointer_vec_str = llvm_vector_str ( bx , element_ty1 , in_len ) ;
1624
1566
1625
1567
// Type of the vector of elements:
1626
- let llvm_elem_vec_ty = llvm_vector_ty ( bx, underlying_ty , in_len, pointer_count - 1 ) ;
1627
- let llvm_elem_vec_str = llvm_vector_str ( underlying_ty , in_len , pointer_count - 1 , bx ) ;
1568
+ let llvm_elem_vec_ty = llvm_vector_ty ( bx, element_ty0 , in_len) ;
1569
+ let llvm_elem_vec_str = llvm_vector_str ( bx , element_ty0 , in_len ) ;
1628
1570
1629
1571
let llvm_intrinsic =
1630
1572
format ! ( "llvm.masked.scatter.{}.{}" , llvm_elem_vec_str, llvm_pointer_vec_str) ;
0 commit comments