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

Method get_static

crates/rustc_codegen_nvvm/src/consts.rs:298–347  ·  view source on GitHub ↗
(&self, def_id: DefId)

Source from the content-addressed store, hash-verified

296 }
297
298 pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value {
299 let instance = Instance::mono(self.tcx, def_id);
300 if let Some(&g) = self.instances.borrow().get(&instance) {
301 return g;
302 }
303
304 let defined_in_current_codegen_unit = self
305 .codegen_unit
306 .items()
307 .contains_key(&MonoItem::Static(def_id));
308 assert!(
309 !defined_in_current_codegen_unit,
310 "consts::get_static() should always hit the cache for \
311 statics defined in the same CGU, but did not for `{:?}`",
312 def_id
313 );
314
315 let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
316 let sym = self.tcx.symbol_name(instance).name;
317 let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
318
319 let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
320 let llty = self.layout_of(ty).llvm_type(self);
321 if let Some(g) = self.get_declared_value(sym) {
322 if self.val_ty(g) != self.type_ptr_to(llty) {
323 span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
324 }
325 }
326
327 let addrspace = self.static_addrspace(instance);
328 let g = self.declare_global(sym, llty, addrspace);
329
330 if !self.tcx.is_reachable_non_generic(def_id) {
331 unsafe {
332 llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
333 }
334 }
335
336 g
337 } else {
338 check_and_apply_linkage(self, fn_attrs, ty, sym, def_id, instance)
339 };
340
341 if fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
342 self.unsupported("thread locals");
343 }
344
345 self.instances.borrow_mut().insert(instance, g);
346 g
347 }
348}
349
350impl<'ll, 'tcx> StaticMethods for CodegenCx<'ll, 'tcx> {

Callers 3

scalar_to_backendMethod · 0.45
codegen_inline_asmMethod · 0.45
codegen_staticMethod · 0.45

Calls 13

LLVMRustSetVisibilityFunction · 0.85
check_and_apply_linkageFunction · 0.85
borrowMethod · 0.80
get_declared_valueMethod · 0.80
val_tyMethod · 0.80
type_ptr_toMethod · 0.80
static_addrspaceMethod · 0.80
declare_globalMethod · 0.80
unsupportedMethod · 0.80
borrow_mutMethod · 0.80
getMethod · 0.45
llvm_typeMethod · 0.45

Tested by

no test coverage detected