Skip to content

Commit 2ec1f6b

Browse files
committed
Parallelize trans
1 parent 9d0639d commit 2ec1f6b

File tree

9 files changed

+230
-196
lines changed

9 files changed

+230
-196
lines changed

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rustc_errors = { path = "../librustc_errors" }
2727
serialize = { path = "../libserialize" }
2828
syntax = { path = "../libsyntax" }
2929
syntax_pos = { path = "../libsyntax_pos" }
30+
num_cpus = "1.0"
3031
backtrace = "0.3.3"
3132
byteorder = { version = "1.1", features = ["i128"]}
3233

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ extern crate fmt_macros;
8585
extern crate getopts;
8686
extern crate graphviz;
8787
#[macro_use] extern crate lazy_static;
88+
extern crate num_cpus;
8889
#[cfg(windows)]
8990
extern crate libc;
9091
#[cfg(windows)]

src/librustc/session/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11631163
"print the AST as JSON and halt"),
11641164
query_threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
11651165
"execute queries on a thread pool with N threads"),
1166+
codegen_threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
1167+
"execute code generation work with N threads"),
11661168
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
11671169
"print the pre-expansion AST as JSON and halt"),
11681170
ls: bool = (false, parse_bool, [UNTRACKED],
@@ -1928,6 +1930,10 @@ pub fn build_session_options_and_crate_config(
19281930
);
19291931
}
19301932

1933+
if debugging_opts.codegen_threads == Some(0) {
1934+
early_error(error_format, "Value for codegen threads must be a positive nonzero integer");
1935+
}
1936+
19311937
if debugging_opts.query_threads.unwrap_or(1) > 1 && debugging_opts.fuel.is_some() {
19321938
early_error(
19331939
error_format,

src/librustc/session/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,12 @@ impl Session {
881881
Self::query_threads_from_opts(&self.opts)
882882
}
883883

884+
/// Returns the number of codegen threads that should be used for this
885+
/// compilation
886+
pub fn codegen_threads(&self) -> usize {
887+
self.opts.debugging_opts.codegen_threads.unwrap_or(::num_cpus::get())
888+
}
889+
884890
/// Returns the number of codegen units that should be used for this
885891
/// compilation
886892
pub fn codegen_units(&self) -> usize {

src/librustc_trans/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ flate2 = "1.0"
1515
jobserver = "0.1.5"
1616
libc = "0.2"
1717
log = "0.4"
18-
num_cpus = "1.0"
18+
rustc-rayon = { git = "https://github.com/Zoxc/rayon.git", branch = "fiber" }
1919
rustc = { path = "../librustc" }
2020
rustc-demangle = "0.1.4"
2121
rustc_allocator = { path = "../librustc_allocator" }

src/librustc_trans/back/lto.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool {
4242
}
4343
}
4444

45+
#[derive(Debug)]
4546
pub(crate) enum LtoModuleTranslation {
4647
Fat {
4748
module: Option<ModuleTranslation>,
@@ -506,6 +507,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
506507
debug!("lto done");
507508
}
508509

510+
#[derive(Debug)]
509511
pub enum SerializedModule {
510512
Local(ModuleBuffer),
511513
FromRlib(Vec<u8>),
@@ -520,6 +522,7 @@ impl SerializedModule {
520522
}
521523
}
522524

525+
#[derive(Debug)]
523526
pub struct ModuleBuffer(*mut llvm::ModuleBuffer);
524527

525528
unsafe impl Send for ModuleBuffer {}
@@ -547,18 +550,21 @@ impl Drop for ModuleBuffer {
547550
}
548551
}
549552

553+
#[derive(Debug)]
550554
pub struct ThinModule {
551555
shared: Arc<ThinShared>,
552556
idx: usize,
553557
}
554558

559+
#[derive(Debug)]
555560
struct ThinShared {
556561
data: ThinData,
557562
thin_buffers: Vec<ThinBuffer>,
558563
serialized_modules: Vec<SerializedModule>,
559564
module_names: Vec<CString>,
560565
}
561566

567+
#[derive(Debug)]
562568
struct ThinData(*mut llvm::ThinLTOData);
563569

564570
unsafe impl Send for ThinData {}
@@ -572,6 +578,7 @@ impl Drop for ThinData {
572578
}
573579
}
574580

581+
#[derive(Debug)]
575582
pub struct ThinBuffer(*mut llvm::ThinLTOBuffer);
576583

577584
unsafe impl Send for ThinBuffer {}

0 commit comments

Comments
 (0)