diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2018-12-04 16:24:20 +0100 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2018-12-04 16:24:20 +0100 |
| commit | 8128d0d1a95f5d77b672558c202cbf37d595fba3 (patch) | |
| tree | 2a63a69c33a1211b7059d3c4025c38484596dad6 /src/librustc_codegen_ssa | |
| parent | bc2db43b9e85c3aeaec021b7d70701233930711f (diff) | |
| download | rust-8128d0d1a95f5d77b672558c202cbf37d595fba3.tar.gz rust-8128d0d1a95f5d77b672558c202cbf37d595fba3.zip | |
Serialize modules into ThinBuffer after initial optimization
Instead of keeping all modules in memory until thin LTO and only serializing them then, serialize the module immediately after it finishes optimizing.
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/back/write.rs | 34 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/traits/write.rs | 6 |
2 files changed, 24 insertions, 16 deletions
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index fe40cb18483..59955ce77cd 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -253,7 +253,7 @@ impl<B: WriteBackendMethods> CodegenContext<B> { fn generate_lto_work<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, needs_fat_lto: Vec<ModuleCodegen<B::Module>>, - needs_thin_lto: Vec<ModuleCodegen<B::Module>>, + needs_thin_lto: Vec<(String, B::ThinBuffer)>, import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)> ) -> Vec<(WorkItem<B>, u64)> { let mut timeline = cgcx.time_graph.as_ref().map(|tg| { @@ -678,17 +678,17 @@ impl<B: WriteBackendMethods> WorkItem<B> { } } -enum WorkItemResult<M> { +enum WorkItemResult<B: WriteBackendMethods> { Compiled(CompiledModule), - NeedsFatLTO(ModuleCodegen<M>), - NeedsThinLTO(ModuleCodegen<M>), + NeedsFatLTO(ModuleCodegen<B::Module>), + NeedsThinLTO(String, B::ThinBuffer), } fn execute_work_item<B: ExtraBackendMethods>( cgcx: &CodegenContext<B>, work_item: WorkItem<B>, timeline: &mut Timeline -) -> Result<WorkItemResult<B::Module>, FatalError> { +) -> Result<WorkItemResult<B>, FatalError> { let module_config = cgcx.config(work_item.module_kind()); match work_item { @@ -716,7 +716,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>( module: ModuleCodegen<B::Module>, module_config: &ModuleConfig, timeline: &mut Timeline -) -> Result<WorkItemResult<B::Module>, FatalError> { +) -> Result<WorkItemResult<B>, FatalError> { let diag_handler = cgcx.create_diag_handler(); unsafe { @@ -772,7 +772,10 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>( }; WorkItemResult::Compiled(module) } - ComputedLtoType::Thin => WorkItemResult::NeedsThinLTO(module), + ComputedLtoType::Thin => { + let (name, thin_buffer) = B::prepare_thin(cgcx, module); + WorkItemResult::NeedsThinLTO(name, thin_buffer) + } ComputedLtoType::Fat => WorkItemResult::NeedsFatLTO(module), }) } @@ -782,7 +785,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>( module: CachedModuleCodegen, module_config: &ModuleConfig, _: &mut Timeline -) -> Result<WorkItemResult<B::Module>, FatalError> { +) -> Result<WorkItemResult<B>, FatalError> { let incr_comp_session_dir = cgcx.incr_comp_session_dir .as_ref() .unwrap(); @@ -844,7 +847,7 @@ fn execute_lto_work_item<B: ExtraBackendMethods>( mut module: lto::LtoModuleCodegen<B>, module_config: &ModuleConfig, timeline: &mut Timeline -) -> Result<WorkItemResult<B::Module>, FatalError> { +) -> Result<WorkItemResult<B>, FatalError> { let diag_handler = cgcx.create_diag_handler(); unsafe { @@ -861,7 +864,8 @@ pub enum Message<B: WriteBackendMethods> { worker_id: usize, }, NeedsThinLTO { - result: ModuleCodegen<B::Module>, + name: String, + thin_buffer: B::ThinBuffer, worker_id: usize, }, Done { @@ -1423,10 +1427,10 @@ fn start_executing_work<B: ExtraBackendMethods>( free_worker(worker_id); needs_fat_lto.push(result); } - Message::NeedsThinLTO { result, worker_id } => { + Message::NeedsThinLTO { name, thin_buffer, worker_id } => { assert!(!started_lto); free_worker(worker_id); - needs_thin_lto.push(result); + needs_thin_lto.push((name, thin_buffer)); } Message::AddImportOnlyModule { module_data, work_product } => { assert!(!started_lto); @@ -1514,7 +1518,7 @@ fn spawn_work<B: ExtraBackendMethods>( // we exit. struct Bomb<B: ExtraBackendMethods> { coordinator_send: Sender<Box<dyn Any + Send>>, - result: Option<WorkItemResult<B::Module>>, + result: Option<WorkItemResult<B>>, worker_id: usize, } impl<B: ExtraBackendMethods> Drop for Bomb<B> { @@ -1527,8 +1531,8 @@ fn spawn_work<B: ExtraBackendMethods>( Some(WorkItemResult::NeedsFatLTO(m)) => { Message::NeedsFatLTO::<B> { result: m, worker_id } } - Some(WorkItemResult::NeedsThinLTO(m)) => { - Message::NeedsThinLTO::<B> { result: m, worker_id } + Some(WorkItemResult::NeedsThinLTO(name, thin_buffer)) => { + Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id } } None => Message::Done::<B> { result: Err(()), worker_id } }; diff --git a/src/librustc_codegen_ssa/traits/write.rs b/src/librustc_codegen_ssa/traits/write.rs index 7b8f9395f85..edc5c2717bc 100644 --- a/src/librustc_codegen_ssa/traits/write.rs +++ b/src/librustc_codegen_ssa/traits/write.rs @@ -36,7 +36,7 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { /// can simply be copied over from the incr. comp. cache. fn run_thin_lto( cgcx: &CodegenContext<Self>, - modules: Vec<ModuleCodegen<Self::Module>>, + modules: Vec<(String, Self::ThinBuffer)>, cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>, timeline: &mut Timeline, ) -> Result<(Vec<LtoModuleCodegen<Self>>, Vec<WorkProduct>), FatalError>; @@ -60,6 +60,10 @@ pub trait WriteBackendMethods: 'static + Sized + Clone { config: &ModuleConfig, timeline: &mut Timeline, ) -> Result<CompiledModule, FatalError>; + fn prepare_thin( + cgcx: &CodegenContext<Self>, + module: ModuleCodegen<Self::Module> + ) -> (String, Self::ThinBuffer); fn run_lto_pass_manager( cgcx: &CodegenContext<Self>, llmod: &ModuleCodegen<Self::Module>, |
