Skip to content

Commit e73e8ec

Browse files
committed
Parallelize trans
1 parent f16710f commit e73e8ec

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
@@ -26,6 +26,7 @@ rustc_errors = { path = "../librustc_errors" }
2626
serialize = { path = "../libserialize" }
2727
syntax = { path = "../libsyntax" }
2828
syntax_pos = { path = "../libsyntax_pos" }
29+
num_cpus = "1.0"
2930
lazy_static = "1.0.0"
3031
backtrace = "0.3.3"
3132
byteorder = { version = "1.1", features = ["i128"]}

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern crate core;
8484
extern crate fmt_macros;
8585
extern crate getopts;
8686
extern crate graphviz;
87+
extern crate num_cpus;
8788
#[cfg(windows)]
8889
extern crate libc;
8990
#[cfg(windows)]

src/librustc/session/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11601160
"print the AST as JSON and halt"),
11611161
query_threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
11621162
"execute queries on a thread pool with N threads"),
1163+
codegen_threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
1164+
"execute code generation work with N threads"),
11631165
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
11641166
"print the pre-expansion AST as JSON and halt"),
11651167
ls: bool = (false, parse_bool, [UNTRACKED],
@@ -1771,6 +1773,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17711773
early_error(error_format, "Value for query threads must be a positive nonzero integer");
17721774
}
17731775

1776+
if debugging_opts.codegen_threads == Some(0) {
1777+
early_error(error_format, "Value for codegen threads must be a positive nonzero integer");
1778+
}
1779+
17741780
if codegen_units == Some(0) {
17751781
early_error(error_format, "Value for codegen units must be a positive nonzero integer");
17761782
}

src/librustc/session/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,12 @@ impl Session {
803803
self.opts.debugging_opts.query_threads.unwrap_or(1)
804804
}
805805

806+
/// Returns the number of codegen threads that should be used for this
807+
/// compilation
808+
pub fn codegen_threads(&self) -> usize {
809+
self.opts.debugging_opts.codegen_threads.unwrap_or(::num_cpus::get())
810+
}
811+
806812
/// Returns the number of codegen units that should be used for this
807813
/// compilation
808814
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+
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>,
@@ -479,6 +480,7 @@ fn run_pass_manager(cgcx: &CodegenContext,
479480
debug!("lto done");
480481
}
481482

483+
#[derive(Debug)]
482484
pub enum SerializedModule {
483485
Local(ModuleBuffer),
484486
FromRlib(Vec<u8>),
@@ -493,6 +495,7 @@ impl SerializedModule {
493495
}
494496
}
495497

498+
#[derive(Debug)]
496499
pub struct ModuleBuffer(*mut llvm::ModuleBuffer);
497500

498501
unsafe impl Send for ModuleBuffer {}
@@ -520,18 +523,21 @@ impl Drop for ModuleBuffer {
520523
}
521524
}
522525

526+
#[derive(Debug)]
523527
pub struct ThinModule {
524528
shared: Arc<ThinShared>,
525529
idx: usize,
526530
}
527531

532+
#[derive(Debug)]
528533
struct ThinShared {
529534
data: ThinData,
530535
thin_buffers: Vec<ThinBuffer>,
531536
serialized_modules: Vec<SerializedModule>,
532537
module_names: Vec<CString>,
533538
}
534539

540+
#[derive(Debug)]
535541
struct ThinData(*mut llvm::ThinLTOData);
536542

537543
unsafe impl Send for ThinData {}
@@ -545,6 +551,7 @@ impl Drop for ThinData {
545551
}
546552
}
547553

554+
#[derive(Debug)]
548555
pub struct ThinBuffer(*mut llvm::ThinLTOBuffer);
549556

550557
unsafe impl Send for ThinBuffer {}

0 commit comments

Comments
 (0)