MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / transmute_llval

Function transmute_llval

crates/rustc_codegen_nvvm/src/int_replace.rs:91–115  ·  view source on GitHub ↗

transmutes a value to a certain type, accounting for structs.

(
    bx: &mut Builder<'ll>,
    cx: &CodegenCx<'ll, '_>,
    a_val: &'ll Value,
    ty: &'ll Type,
)

Source from the content-addressed store, hash-verified

89
90/// transmutes a value to a certain type, accounting for structs.
91pub(crate) fn transmute_llval<'ll>(
92 bx: &mut Builder<'ll>,
93 cx: &CodegenCx<'ll, '_>,
94 a_val: &'ll Value,
95 ty: &'ll Type,
96) -> &'ll Value {
97 trace!("transmute_llval: transmuting `{:?}` to `{:?}`", a_val, ty);
98 unsafe {
99 let kind = LLVMRustGetTypeKind(ty);
100 match kind {
101 // structs cannot be bitcasted, so we need to do it using a bunch of extract/insert values.
102 TypeKind::Struct => {
103 let new_struct = LLVMGetUndef(ty);
104 let mut last_val = new_struct;
105 for (idx, field) in struct_type_fields(ty).into_iter().enumerate() {
106 let field_val = LLVMBuildExtractValue(bx, a_val, idx as u32, unnamed());
107 let new_val = transmute_llval(bx, cx, field_val, field);
108 last_val = LLVMBuildInsertValue(bx, last_val, new_val, idx as u32, unnamed());
109 }
110 last_val
111 }
112 _ => LLVMBuildBitCast(bx, a_val, ty, unnamed()),
113 }
114 }
115}

Callers 3

get_paramMethod · 0.85
retMethod · 0.85
callMethod · 0.85

Calls 3

LLVMRustGetTypeKindFunction · 0.85
struct_type_fieldsFunction · 0.85
unnamedFunction · 0.85

Tested by

no test coverage detected