Skip to content

Commit

Permalink
Fix performance regression in debuginfo file_metadata.
Browse files Browse the repository at this point in the history
Finding the `SourceFile` associated with a `FileName` called `get_source_file` on
the `SourceMap`, which does a linear search through all files in the `SourceMap`.

This resolves the issue by passing the SourceFile in from the caller (which already
had it available).
  • Loading branch information
arlosi committed Apr 5, 2020
1 parent 853c477 commit 4cdceda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Expand Up @@ -76,7 +76,7 @@ fn make_mir_scope(
}

let loc = cx.lookup_debug_loc(scope_data.span.lo());
let file_metadata = file_metadata(cx, &loc.file.name, debug_context.defining_crate);
let file_metadata = file_metadata(cx, &loc.file, debug_context.defining_crate);

let scope_metadata = unsafe {
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Expand Up @@ -41,7 +41,7 @@ use rustc_middle::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_session::config::{self, DebugInfo};
use rustc_span::symbol::{Interner, Symbol};
use rustc_span::{self, FileName, SourceFileHash, Span};
use rustc_span::{self, SourceFile, SourceFileHash, Span};
use rustc_target::abi::{Abi, Align, DiscriminantKind, HasDataLayout, Integer, LayoutOf};
use rustc_target::abi::{Int, Pointer, F32, F64};
use rustc_target::abi::{Primitive, Size, VariantIdx, Variants};
Expand Down Expand Up @@ -761,14 +761,13 @@ fn hex_encode(data: &[u8]) -> String {

pub fn file_metadata(
cx: &CodegenCx<'ll, '_>,
file_name: &FileName,
source_file: &SourceFile,
defining_crate: CrateNum,
) -> &'ll DIFile {
debug!("file_metadata: file_name: {}, defining_crate: {}", file_name, defining_crate);
debug!("file_metadata: file_name: {}, defining_crate: {}", source_file.name, defining_crate);

let source_file = cx.sess().source_map().get_source_file(file_name);
let hash = source_file.as_ref().map(|f| &f.src_hash);
let file_name = Some(file_name.to_string());
let hash = Some(&source_file.src_hash);
let file_name = Some(source_file.name.to_string());
let directory = if defining_crate == LOCAL_CRATE {
Some(cx.sess().working_dir.0.to_string_lossy().to_string())
} else {
Expand Down Expand Up @@ -2331,7 +2330,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global

let (file_metadata, line_number) = if !span.is_dummy() {
let loc = cx.lookup_debug_loc(span.lo());
(file_metadata(cx, &loc.file.name, LOCAL_CRATE), loc.line)
(file_metadata(cx, &loc.file, LOCAL_CRATE), loc.line)
} else {
(unknown_file_metadata(cx), None)
};
Expand Down Expand Up @@ -2440,6 +2439,6 @@ pub fn extend_scope_to_file(
file: &rustc_span::SourceFile,
defining_crate: CrateNum,
) -> &'ll DILexicalBlock {
let file_metadata = file_metadata(cx, &file.name, defining_crate);
let file_metadata = file_metadata(cx, &file, defining_crate);
unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) }
}
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Expand Up @@ -249,7 +249,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let def_id = instance.def_id();
let containing_scope = get_containing_scope(self, instance);
let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file.name, def_id.krate);
let file_metadata = file_metadata(self, &loc.file, def_id.krate);

let function_type_metadata = unsafe {
let fn_signature = get_function_signature(self, fn_abi);
Expand Down Expand Up @@ -536,7 +536,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
span: Span,
) -> &'ll DIVariable {
let loc = self.lookup_debug_loc(span.lo());
let file_metadata = file_metadata(self, &loc.file.name, dbg_context.defining_crate);
let file_metadata = file_metadata(self, &loc.file, dbg_context.defining_crate);

let type_metadata = type_metadata(self, variable_type, span);

Expand Down

0 comments on commit 4cdceda

Please sign in to comment.