A "scalar" is a basic building block: bools, ints, floats, pointers. (i.e. not something complex like a struct) A "scalar pair" is a bit of a strange concept: if there is a `fn f(x: (u32, u32))`, then what's preferred for performance is to compile that ABI to `f(x_1: u32, x_2: u32)`, i.e. splitting out the pair into their own arguments, and pretending that they're one unit. So, there's quite a bit
(
cx: &CodegenCx<'tcx>,
span: Span,
ty: TyAndLayout<'tcx>,
scalar: Scalar,
offset: Size,
)
| 488 | /// I say it's "preferred", but spirv doesn't really care - only CPU ABIs really care here. However, following rustc's |
| 489 | /// lead and doing what they want makes things go smoothly, so we'll implement it here too. |
| 490 | fn trans_scalar<'tcx>( |
| 491 | cx: &CodegenCx<'tcx>, |
| 492 | span: Span, |
| 493 | ty: TyAndLayout<'tcx>, |
| 494 | scalar: Scalar, |
| 495 | offset: Size, |
| 496 | ) -> Word { |
| 497 | if scalar.is_bool() { |
| 498 | return SpirvType::Bool.def(span, cx); |
| 499 | } |
| 500 | |
| 501 | match scalar.primitive() { |
| 502 | Primitive::Int(width, signedness) => { |
| 503 | SpirvType::Integer(width.size().bits() as u32, signedness).def(span, cx) |
| 504 | } |
| 505 | Primitive::F32 => SpirvType::Float(32).def(span, cx), |
| 506 | Primitive::F64 => SpirvType::Float(64).def(span, cx), |
| 507 | Primitive::Pointer(_) => { |
| 508 | let pointee_ty = dig_scalar_pointee(cx, ty, offset); |
| 509 | // Pointers can be recursive. So, record what we're currently translating, and if we're already translating |
| 510 | // the same type, emit an OpTypeForwardPointer and use that ID. |
| 511 | if let Some(predefined_result) = cx |
| 512 | .type_cache |
| 513 | .recursive_pointee_cache |
| 514 | .begin(cx, span, pointee_ty) |
| 515 | { |
| 516 | predefined_result |
| 517 | } else { |
| 518 | let pointee = pointee_ty.spirv_type(span, cx); |
| 519 | cx.type_cache |
| 520 | .recursive_pointee_cache |
| 521 | .end(cx, span, pointee_ty, pointee) |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | // This is a really weird function, strap in... |
| 528 | // So, rustc_codegen_ssa is designed around scalar pointers being opaque, you shouldn't know the type behind the |
no test coverage detected