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

Drive trans from the output of the translation item collector #33890

Merged
merged 21 commits into from
Jul 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
891c2a0
trans: Make translation of statics collector-driven.
michaelwoerister May 7, 2016
6717106
Drive function item translation from collector
Aatch May 13, 2016
5f3fefc
trans: Get rid of the last potential on-demand creation of non-closur…
michaelwoerister May 13, 2016
2cd8cf9
Ignore closure-related translation item collection tests.
michaelwoerister May 14, 2016
65e8a13
Adapt backend to trans::partitioning dictating the codegen-unit setup.
michaelwoerister May 14, 2016
6c8c94b
Improve linkage assignment in trans::partitioning.
michaelwoerister May 19, 2016
87c1c87
Make drop-glue translation collector-driven.
michaelwoerister May 10, 2016
b38e0d0
Build SymbolMap for symbol name conflict checking and caching.
michaelwoerister May 26, 2016
37a10ec
Make item translation order deterministic by sorting by symbol name.
michaelwoerister May 26, 2016
283c94c
Clean up trans::trans_crate() after making things collector driven.
michaelwoerister May 26, 2016
3a47103
Fix codegen tests by make sure items are translated in AST order.
michaelwoerister May 26, 2016
00226fc
Pacify make tidy.
michaelwoerister May 26, 2016
ab80f74
collector-driven-trans: Take care of nits.
michaelwoerister Jun 2, 2016
b33240e
trans::collector: Also consider initializers of const items.
michaelwoerister Jun 2, 2016
4a3f9b8
hir-trans: Don't generate code for unreachable operands in short-circ…
michaelwoerister Jun 3, 2016
a7bc0b9
trans: Add missing normalize_associated_type() call to callee::get_fn().
michaelwoerister Jun 8, 2016
4c27a3c
trans: Enable falling back to on-demand instantiation for drop-glue a…
michaelwoerister Jun 8, 2016
b149b9d
trans: Set COMDAT section for weak symbols so that Windows can handle…
michaelwoerister Jun 9, 2016
ac80d41
trans: Remove tracking of translation item state.
michaelwoerister Jun 16, 2016
051d391
Update LLVM.
michaelwoerister Jun 22, 2016
1c03bfe
trans: Adjust linkage assignment so that we don't need weak linkage.
michaelwoerister Jun 10, 2016
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
65 changes: 56 additions & 9 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,70 @@ pub struct OutputFilenames {
pub outputs: HashMap<OutputType, Option<PathBuf>>,
}

/// Codegen unit names generated by the numbered naming scheme will contain this
/// marker right before the index of the codegen unit.
pub const NUMBERED_CODEGEN_UNIT_MARKER: &'static str = ".cgu-";

impl OutputFilenames {
pub fn path(&self, flavor: OutputType) -> PathBuf {
self.outputs.get(&flavor).and_then(|p| p.to_owned())
.or_else(|| self.single_output_file.clone())
.unwrap_or_else(|| self.temp_path(flavor))
.unwrap_or_else(|| self.temp_path(flavor, None))
}

pub fn temp_path(&self, flavor: OutputType) -> PathBuf {
/// Get the path where a compilation artifact of the given type for the
/// given codegen unit should be placed on disk. If codegen_unit_name is
/// None, a path distinct from those of any codegen unit will be generated.
pub fn temp_path(&self,
flavor: OutputType,
codegen_unit_name: Option<&str>)
-> PathBuf {
let extension = match flavor {
OutputType::Bitcode => "bc",
OutputType::Assembly => "s",
OutputType::LlvmAssembly => "ll",
OutputType::Object => "o",
OutputType::DepInfo => "d",
OutputType::Exe => "",
};

self.temp_path_ext(extension, codegen_unit_name)
}

/// Like temp_path, but also supports things where there is no corresponding
/// OutputType, like no-opt-bitcode or lto-bitcode.
pub fn temp_path_ext(&self,
ext: &str,
codegen_unit_name: Option<&str>)
-> PathBuf {
let base = self.out_directory.join(&self.filestem());
match flavor {
OutputType::Bitcode => base.with_extension("bc"),
OutputType::Assembly => base.with_extension("s"),
OutputType::LlvmAssembly => base.with_extension("ll"),
OutputType::Object => base.with_extension("o"),
OutputType::DepInfo => base.with_extension("d"),
OutputType::Exe => base,

let mut extension = String::new();

if let Some(codegen_unit_name) = codegen_unit_name {
if codegen_unit_name.contains(NUMBERED_CODEGEN_UNIT_MARKER) {
// If we use the numbered naming scheme for modules, we don't want
// the files to look like <crate-name><extra>.<crate-name>.<index>.<ext>
// but simply <crate-name><extra>.<index>.<ext>
let marker_offset = codegen_unit_name.rfind(NUMBERED_CODEGEN_UNIT_MARKER)
.unwrap();
let index_offset = marker_offset + NUMBERED_CODEGEN_UNIT_MARKER.len();
extension.push_str(&codegen_unit_name[index_offset .. ]);
} else {
extension.push_str(codegen_unit_name);
};
}

if !ext.is_empty() {
if !extension.is_empty() {
extension.push_str(".");
}

extension.push_str(ext);
}

let path = base.with_extension(&extension[..]);
path
}

pub fn with_extension(&self, extension: &str) -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,

// Remove assembly source, unless --save-temps was specified
if !sess.opts.cg.save_temps {
fs::remove_file(&outputs.temp_path(OutputType::Assembly)).unwrap();
fs::remove_file(&outputs.temp_path(OutputType::Assembly, None)).unwrap();
}
} else {
time(sess.time_passes(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_trans/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl ArgType {
///
/// I will do my best to describe this structure, but these
/// comments are reverse-engineered and may be inaccurate. -NDM
#[derive(Clone)]
pub struct FnType {
/// The LLVM types of each argument.
pub args: Vec<ArgType>,
Expand Down
15 changes: 8 additions & 7 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub fn link_binary(sess: &Session,

// Remove the temporary object file and metadata if we aren't saving temps
if !sess.opts.cg.save_temps {
for obj in object_filenames(sess, outputs) {
for obj in object_filenames(trans, outputs) {
remove(sess, &obj);
}
remove(sess, &outputs.with_extension("metadata.o"));
Expand Down Expand Up @@ -316,7 +316,7 @@ fn link_binary_output(sess: &Session,
crate_type: config::CrateType,
outputs: &OutputFilenames,
crate_name: &str) -> PathBuf {
let objects = object_filenames(sess, outputs);
let objects = object_filenames(trans, outputs);
let default_filename = filename_for_input(sess, crate_type, crate_name,
outputs);
let out_filename = outputs.outputs.get(&OutputType::Exe)
Expand Down Expand Up @@ -356,10 +356,11 @@ fn link_binary_output(sess: &Session,
out_filename
}

fn object_filenames(sess: &Session, outputs: &OutputFilenames) -> Vec<PathBuf> {
(0..sess.opts.cg.codegen_units).map(|i| {
let ext = format!("{}.o", i);
outputs.temp_path(OutputType::Object).with_extension(&ext)
fn object_filenames(trans: &CrateTranslation,
outputs: &OutputFilenames)
-> Vec<PathBuf> {
trans.modules.iter().map(|module| {
outputs.temp_path(OutputType::Object, Some(&module.name[..]))
}).collect()
}

Expand Down Expand Up @@ -497,7 +498,7 @@ fn link_rlib<'a>(sess: &'a Session,
ab.add_file(&bc_deflated_filename);

// See the bottom of back::write::run_passes for an explanation
// of when we do and don't keep .0.bc files around.
// of when we do and don't keep .#module-name#.bc files around.
let user_wants_numbered_bitcode =
sess.opts.output_types.contains_key(&OutputType::Bitcode) &&
sess.opts.cg.codegen_units > 1;
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_trans/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use libc;
use flate;

use std::ffi::CString;
use std::path::Path;

pub fn run(sess: &session::Session, llmod: ModuleRef,
tm: TargetMachineRef, reachable: &[String],
config: &ModuleConfig,
name_extra: &str,
output_names: &config::OutputFilenames) {
temp_no_opt_bc_filename: &Path) {
if sess.opts.cg.prefer_dynamic {
sess.struct_err("cannot prefer dynamic linking when performing LTO")
.note("only 'staticlib', 'bin', and 'cdylib' outputs are \
Expand Down Expand Up @@ -132,8 +132,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
}

if sess.opts.cg.save_temps {
let path = output_names.with_extension(&format!("{}.no-opt.lto.bc", name_extra));
let cstr = path2cstr(&path);
let cstr = path2cstr(temp_no_opt_bc_filename);
unsafe {
llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
}
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_trans/back/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ impl ItemPathBuffer for SymbolPathBuffer {
}
}

pub fn exported_name_from_type_and_prefix<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
t: ty::Ty<'tcx>,
prefix: &str)
-> String {
let empty_def_path = DefPath {
data: vec![],
krate: cstore::LOCAL_CRATE,
};
let hash = get_symbol_hash(scx, &empty_def_path, t, &[]);
let path = [token::intern_and_get_ident(prefix)];
mangle(path.iter().cloned(), Some(&hash[..]))
}

/// Only symbols that are invisible outside their compilation unit should use a
/// name generated by this function.
pub fn internal_name_from_type_and_suffix<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
Expand Down
Loading