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

Method from_const_alloc

crates/rustc_codegen_nvvm/src/const_ty.rs:195–220  ·  view source on GitHub ↗
(
        &self,
        layout: TyAndLayout<'tcx>,
        alloc: &Allocation,
        offset: Size,
    )

Source from the content-addressed store, hash-verified

193 }
194
195 fn from_const_alloc(
196 &self,
197 layout: TyAndLayout<'tcx>,
198 alloc: &Allocation,
199 offset: Size,
200 ) -> PlaceRef<'tcx, &'ll Value> {
201 assert_eq!(alloc.align, layout.align.abi);
202 let llty = self.type_ptr_to(layout.llvm_type(self));
203 let llval = if layout.size == Size::ZERO {
204 let llval = self.const_usize(alloc.align.bytes());
205 unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
206 } else {
207 let init = const_alloc_to_llvm(self, alloc);
208 let base_addr = self.static_addr_of(init, alloc.align, None);
209
210 let llval = unsafe {
211 llvm::LLVMConstInBoundsGEP(
212 self.const_bitcast(base_addr, self.type_i8p()),
213 &self.const_usize(offset.bytes()),
214 1,
215 )
216 };
217 self.const_bitcast(llval, llty)
218 };
219 PlaceRef::new_sized(llval, layout)
220 }
221
222 fn const_ptrcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
223 unsafe { llvm::LLVMConstPointerCast(val, ty) }

Callers

nothing calls this directly

Calls 6

const_alloc_to_llvmFunction · 0.85
type_ptr_toMethod · 0.80
const_usizeMethod · 0.80
static_addr_ofMethod · 0.80
const_bitcastMethod · 0.80
llvm_typeMethod · 0.45

Tested by

no test coverage detected