(self, cx: &CodegenCx<'_>)
| 77 | |
| 78 | impl 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 |
no test coverage detected