]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_llvm/src/debuginfo/utils.rs
New upstream version 1.59.0+dfsg1
[rustc.git] / compiler / rustc_codegen_llvm / src / debuginfo / utils.rs
CommitLineData
d9579d0f
AL
1// Utility Functions.
2
a7813a04 3use super::namespace::item_namespace;
dfeec247 4use super::CrateDebugContext;
d9579d0f 5
dfeec247 6use rustc_hir::def_id::DefId;
ba9703b0 7use rustc_middle::ty::DefIdTree;
e9174d1e 8
dfeec247 9use crate::common::CodegenCx;
9fa01778 10use crate::llvm;
dfeec247 11use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
d9579d0f 12
dfeec247 13pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
d9579d0f 14 // The is_local_to_unit flag indicates whether a function is local to the
0731742a 15 // current compilation unit (i.e., if it is *static* in the C-sense). The
d9579d0f
AL
16 // *reachable* set should provide a good approximation of this, as it
17 // contains everything that might leak out of the current crate (by being
18 // externally visible or by being inlined into something externally
19 // visible). It might better to use the `exported_items` set from
20 // `driver::CrateAnalysis` in the future, but (atm) this set is not
94b46f34 21 // available in the codegen pass.
0531ce1d 22 !cx.tcx.is_reachable_non_generic(def_id)
d9579d0f
AL
23}
24
25#[allow(non_snake_case)]
a2a8927a
XL
26pub fn create_DIArray<'ll>(
27 builder: &DIBuilder<'ll>,
28 arr: &[Option<&'ll DIDescriptor>],
29) -> &'ll DIArray {
ba9703b0 30 unsafe { llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) }
d9579d0f
AL
31}
32
d9579d0f 33#[inline]
a2a8927a
XL
34pub fn debug_context<'a, 'll, 'tcx>(
35 cx: &'a CodegenCx<'ll, 'tcx>,
36) -> &'a CrateDebugContext<'ll, 'tcx> {
2c00a5a8 37 cx.dbg_cx.as_ref().unwrap()
d9579d0f
AL
38}
39
40#[inline]
41#[allow(non_snake_case)]
a2a8927a 42pub fn DIB<'a, 'll>(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
2c00a5a8 43 cx.dbg_cx.as_ref().unwrap().builder
d9579d0f
AL
44}
45
a2a8927a 46pub fn get_namespace_for_item<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
dfeec247 47 item_namespace(cx, cx.tcx.parent(def_id).expect("get_namespace_for_item: missing parent?"))
d9579d0f 48}