Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(attr): Gen & pass JITDwarfShortName on demand #481

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_attr::InstructionSetAttr;
#[cfg(feature = "master")]
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty;
use rustc_session::config::DebugInfo;
use rustc_span::symbol::sym;

use crate::gcc_util::{check_tied_features, to_gcc_features};
Expand Down Expand Up @@ -40,7 +41,8 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
#[cfg_attr(not(feature = "master"), allow(unused_variables))] func: Function<'gcc>,
instance: ty::Instance<'tcx>,
) {
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
let def_id = instance.def_id();
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(def_id);

#[cfg(feature = "master")]
{
Expand Down Expand Up @@ -69,6 +71,16 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_CONST) {
func.add_attribute(FnAttribute::Const);
}
if cx.sess().opts.debuginfo != DebugInfo::None
&& !codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
&& codegen_fn_attrs.export_name.is_none()
{
let parent = cx.get_or_create_module(&instance);
let signature = cx.tcx.symbol_name(instance).to_string();
//let signature = cx.tcx.def_path_str(instance.def_id());
func.add_attribute(FnAttribute::JITDwarfShortName(signature));
func.set_parent_debug_namespace(parent);
}
}

let function_features = codegen_fn_attrs
Expand Down
5 changes: 5 additions & 0 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ pub fn compile_codegen_unit(
{
let cx = CodegenCx::new(&context, cgu, tcx, target_info.supports_128bit_int());

// This should be set before the code is generated.
if cx.sess().opts.debuginfo != DebugInfo::None {
context.set_mangled_function_name(true);
}

let mono_items = cgu.items_in_deterministic_order(tcx);
for &(mono_item, data) in &mono_items {
mono_item.predefine::<Builder<'_, '_, '_>>(&cx, data.linkage, data.visibility);
Expand Down
5 changes: 4 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::cell::{Cell, RefCell};

use gccjit::{
Block, CType, Context, Function, FunctionPtrType, FunctionType, LValue, Location, RValue, Type,
Block, CType, Context, DebugNamespace, Function, FunctionPtrType, FunctionType, LValue,
Location, RValue, Type,
};
use rustc_codegen_ssa::base::wants_msvc_seh;
use rustc_codegen_ssa::errors as ssa_errors;
Expand Down Expand Up @@ -86,6 +87,7 @@ pub struct CodegenCx<'gcc, 'tcx> {
/// Cache generated vtables
pub vtables:
RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), RValue<'gcc>>>,
pub modules: RefCell<FxHashMap<Instance<'tcx>, DebugNamespace>>,

// TODO(antoyo): improve the SSA API to not require those.
/// Mapping from function pointer type to indexes of on stack parameters.
Expand Down Expand Up @@ -315,6 +317,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
on_stack_params: Default::default(),
on_stack_function_params: Default::default(),
vtables: Default::default(),
modules: Default::default(),
const_globals: Default::default(),
global_lvalues: Default::default(),
const_str_cache: Default::default(),
Expand Down
27 changes: 25 additions & 2 deletions src/declare.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use gccjit::{DebugNamespace, Function, FunctionType, GlobalKind, LValue, RValue, Type};
#[cfg(feature = "master")]
use gccjit::{FnAttribute, ToRValue};
use gccjit::{Function, FunctionType, GlobalKind, LValue, RValue, Type};
use rustc_codegen_ssa::traits::BaseTypeMethods;
use rustc_middle::ty::Ty;
//use rustc_middle::query::Key;
use rustc_middle::ty::{Instance, Ty};
use rustc_span::Symbol;
use rustc_target::abi::call::FnAbi;

Expand Down Expand Up @@ -153,6 +154,28 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
// TODO(antoyo): use a different field than globals, because this seems to return a function?
self.globals.borrow().get(name).cloned()
}

#[inline]
pub fn get_or_create_module(&self, instance: &Instance<'tcx>) -> DebugNamespace {
let mut bor = self.modules.borrow_mut();
if let Some(debug_namespace) = bor.get(&instance) {
*debug_namespace
} else {

let parent = None;
/* let parent = if let Some(parent) = self.tcx.opt_parent(instance.def_id()) {
* let parent = todo!();
* Some(self.get_or_create_module(parent))
* } else {
* None
* }; */
let name = self.tcx.symbol_name(*instance).name;

let debug_namespace = self.context.new_debug_namespace(name, parent);
bor.insert(*instance, debug_namespace);
*bor.get(&instance).unwrap()
}
}
}

/// Declare a function.
Expand Down
Loading