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

Method def_constant_cx

crates/rustc_codegen_spirv/src/builder_spirv.rs:535–659  ·  view source on GitHub ↗
(
        &self,
        ty: Word,
        val: SpirvConst<'_>,
        cx: &CodegenCx<'tcx>,
    )

Source from the content-addressed store, hash-verified

533 }
534
535 pub(crate) fn def_constant_cx(
536 &self,
537 ty: Word,
538 val: SpirvConst<'_>,
539 cx: &CodegenCx<'tcx>,
540 ) -> SpirvValue {
541 let val_with_type = WithType { ty, val };
542 let mut builder = self.builder(BuilderCursor::default());
543 if let Some(entry) = self.const_to_id.borrow().get(&val_with_type) {
544 // FIXME(eddyb) deduplicate this `if`-`else` and its other copies.
545 let kind = if entry.legal.is_ok() {
546 SpirvValueKind::Def(entry.val)
547 } else {
548 SpirvValueKind::IllegalConst(entry.val)
549 };
550 return SpirvValue { kind, ty };
551 }
552 let val = val_with_type.val;
553 let id = match val {
554 SpirvConst::U32(v) => builder.constant_u32(ty, v),
555 SpirvConst::U64(v) => builder.constant_u64(ty, v),
556 SpirvConst::F32(v) => builder.constant_f32(ty, f32::from_bits(v)),
557 SpirvConst::F64(v) => builder.constant_f64(ty, f64::from_bits(v)),
558 SpirvConst::Bool(v) => {
559 if v {
560 builder.constant_true(ty)
561 } else {
562 builder.constant_false(ty)
563 }
564 }
565
566 SpirvConst::Null => builder.constant_null(ty),
567 SpirvConst::Undef | SpirvConst::ZombieUndefForFnAddr => builder.undef(ty, None),
568
569 SpirvConst::Composite(v) => builder.constant_composite(ty, v.iter().copied()),
570
571 SpirvConst::PtrTo { pointee } => {
572 builder.variable(ty, None, StorageClass::Private, Some(pointee))
573 }
574 };
575 #[allow(clippy::match_same_arms)]
576 let legal = match val {
577 SpirvConst::U32(_)
578 | SpirvConst::U64(_)
579 | SpirvConst::F32(_)
580 | SpirvConst::F64(_)
581 | SpirvConst::Bool(_) => Ok(()),
582
583 SpirvConst::Null => {
584 // FIXME(eddyb) check that the type supports `OpConstantNull`.
585 Ok(())
586 }
587 SpirvConst::Undef => {
588 // FIXME(eddyb) check that the type supports `OpUndef`.
589 Ok(())
590 }
591
592 SpirvConst::ZombieUndefForFnAddr => {

Callers 1

def_constantMethod · 0.80

Calls 13

IllegalConstEnum · 0.85
builderMethod · 0.80
constant_u32Method · 0.80
constant_u64Method · 0.80
constant_f32Method · 0.80
constant_f64Method · 0.80
constant_nullMethod · 0.80
undefMethod · 0.80
constant_compositeMethod · 0.80
iterMethod · 0.80
getMethod · 0.45
andMethod · 0.45

Tested by

no test coverage detected