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

Method pointercast

crates/rustc_codegen_spirv/src/builder/builder_methods.rs:1612–1667  ·  view source on GitHub ↗
(&mut self, val: Self::Value, dest_ty: Self::Type)

Source from the content-addressed store, hash-verified

1610 }
1611
1612 fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value {
1613 let (val, val_pointee) = match val.kind {
1614 // Strip a previous `pointercast`, to reveal the original pointer type.
1615 SpirvValueKind::LogicalPtrCast {
1616 original_ptr,
1617 original_pointee_ty,
1618 bitcast_result_id: _,
1619 } => (
1620 original_ptr.with_type(
1621 SpirvType::Pointer {
1622 pointee: original_pointee_ty,
1623 }
1624 .def(self.span(), self),
1625 ),
1626 original_pointee_ty,
1627 ),
1628
1629 _ => match self.lookup_type(val.ty) {
1630 SpirvType::Pointer { pointee } => (val, pointee),
1631 other => self.fatal(&format!(
1632 "pointercast called on non-pointer source type: {other:?}"
1633 )),
1634 },
1635 };
1636 let dest_pointee = match self.lookup_type(dest_ty) {
1637 SpirvType::Pointer { pointee } => pointee,
1638 other => self.fatal(&format!(
1639 "pointercast called on non-pointer dest type: {other:?}"
1640 )),
1641 };
1642 if val.ty == dest_ty {
1643 val
1644 } else if let Some(indices) =
1645 self.recover_access_chain_from_offset(val_pointee, dest_pointee, Size::ZERO)
1646 {
1647 let indices = indices
1648 .into_iter()
1649 .map(|idx| self.constant_u32(self.span(), idx).def(self))
1650 .collect::<Vec<_>>();
1651 self.emit()
1652 .access_chain(dest_ty, None, val.def(self), indices)
1653 .unwrap()
1654 .with_type(dest_ty)
1655 } else {
1656 // Defer the cast so that it has a chance to be avoided.
1657 let original_ptr = val.def(self);
1658 SpirvValue {
1659 kind: SpirvValueKind::LogicalPtrCast {
1660 original_ptr,
1661 original_pointee_ty: val_pointee,
1662 bitcast_result_id: self.emit().bitcast(dest_ty, None, original_ptr).unwrap(),
1663 },
1664 ty: dest_ty,
1665 }
1666 }
1667 }
1668
1669 fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value {

Callers 1

bitcastMethod · 0.80

Calls 10

with_typeMethod · 0.80
spanMethod · 0.80
lookup_typeMethod · 0.80
fatalMethod · 0.80
into_iterMethod · 0.80
constant_u32Method · 0.80
bitcastMethod · 0.80
defMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected