MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / trans_scalar

Function trans_scalar

crates/rustc_codegen_spirv/src/abi.rs:490–525  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
490fn 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

Callers 2

spirv_typeMethod · 0.85

Calls 7

IntegerInterface · 0.85
FloatInterface · 0.85
dig_scalar_pointeeFunction · 0.85
beginMethod · 0.80
spirv_typeMethod · 0.80
endMethod · 0.80
defMethod · 0.45

Tested by

no test coverage detected