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

Method const_fold_load

crates/rustc_codegen_spirv/src/builder_spirv.rs:79–103  ·  view source on GitHub ↗
(self, cx: &CodegenCx<'_>)

Source from the content-addressed store, hash-verified

77
78impl SpirvValue {
79 pub fn const_fold_load(self, cx: &CodegenCx<'_>) -> Option<Self> {
80 match self.kind {
81 SpirvValueKind::Def(id) | SpirvValueKind::IllegalConst(id) => {
82 let &entry = cx.builder.id_to_const.borrow().get(&id)?;
83 match entry.val {
84 SpirvConst::PtrTo { pointee } => {
85 let ty = match cx.lookup_type(self.ty) {
86 SpirvType::Pointer { pointee } => pointee,
87 ty => bug!("load called on value that wasn't a pointer: {:?}", ty),
88 };
89 // FIXME(eddyb) deduplicate this `if`-`else` and its other copies.
90 let kind = if entry.legal.is_ok() {
91 SpirvValueKind::Def(pointee)
92 } else {
93 SpirvValueKind::IllegalConst(pointee)
94 };
95 Some(SpirvValue { kind, ty })
96 }
97 _ => None,
98 }
99 }
100
101 _ => None,
102 }
103 }
104
105 // Important: we *cannot* use bx.emit() here, because this is called in
106 // contexts where the emitter is already locked. Doing so may cause subtle

Callers 2

loadMethod · 0.80
memcpyMethod · 0.80

Calls 3

IllegalConstEnum · 0.85
lookup_typeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected