diff options
Diffstat (limited to 'src/librustc_codegen_llvm/lib.rs')
| -rw-r--r-- | src/librustc_codegen_llvm/lib.rs | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 1e1d74cfa9a..2c1c9427e8c 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -5,7 +5,6 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] - #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(box_syntax)] @@ -21,25 +20,25 @@ #![feature(static_nobundle)] #![feature(trusted_len)] -use back::write::{create_target_machine, create_informational_target_machine}; +use back::write::{create_informational_target_machine, create_target_machine}; use syntax_pos::symbol::Symbol; +pub use llvm_util::target_features; +use rustc::dep_graph::WorkProduct; +use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule}; +use rustc_codegen_ssa::back::write::{CodegenContext, FatLTOInput, ModuleConfig}; use rustc_codegen_ssa::traits::*; -use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, FatLTOInput}; -use rustc_codegen_ssa::back::lto::{SerializedModule, LtoModuleCodegen, ThinModule}; use rustc_codegen_ssa::CompiledModule; use rustc_errors::{FatalError, Handler}; -use rustc::dep_graph::WorkProduct; -use syntax::expand::allocator::AllocatorKind; -pub use llvm_util::target_features; use std::any::Any; -use std::sync::Arc; use std::ffi::CStr; +use std::sync::Arc; +use syntax::expand::allocator::AllocatorKind; use rustc::dep_graph::DepGraph; use rustc::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; +use rustc::session::config::{OptLevel, OutputFilenames, OutputType, PrintRequest}; use rustc::session::Session; -use rustc::session::config::{OutputFilenames, OutputType, PrintRequest, OptLevel}; use rustc::ty::{self, TyCtxt}; use rustc::util::common::ErrorReported; use rustc_codegen_ssa::ModuleCodegen; @@ -67,15 +66,19 @@ mod declare; mod intrinsic; // The following is a work around that replaces `pub mod llvm;` and that fixes issue 53912. -#[path = "llvm/mod.rs"] mod llvm_; pub mod llvm { pub use super::llvm_::*; } +#[path = "llvm/mod.rs"] +mod llvm_; +pub mod llvm { + pub use super::llvm_::*; +} mod llvm_util; mod metadata; mod mono_item; mod type_; mod type_of; -mod value; mod va_arg; +mod value; #[derive(Clone)] pub struct LlvmCodegenBackend(()); @@ -102,7 +105,8 @@ impl ExtraBackendMethods for LlvmCodegenBackend { unsafe { allocator::codegen(tcx, mods, kind) } } fn compile_codegen_unit( - &self, tcx: TyCtxt<'_>, + &self, + tcx: TyCtxt<'_>, cgu_name: Symbol, tx: &std::sync::mpsc::Sender<Box<dyn Any + Send>>, ) { @@ -112,9 +116,8 @@ impl ExtraBackendMethods for LlvmCodegenBackend { &self, sess: &Session, optlvl: OptLevel, - find_features: bool - ) -> Arc<dyn Fn() -> - Result<&'static mut llvm::TargetMachine, String> + Send + Sync> { + find_features: bool, + ) -> Arc<dyn Fn() -> Result<&'static mut llvm::TargetMachine, String> + Send + Sync> { back::write::target_machine_factory(sess, optlvl, find_features) } fn target_cpu<'b>(&self, sess: &'b Session) -> &'b str { @@ -130,7 +133,9 @@ impl WriteBackendMethods for LlvmCodegenBackend { type ThinData = back::lto::ThinData; type ThinBuffer = back::lto::ThinBuffer; fn print_pass_timings(&self) { - unsafe { llvm::LLVMRustPrintPassTimings(); } + unsafe { + llvm::LLVMRustPrintPassTimings(); + } } fn run_fat_lto( cgcx: &CodegenContext<Self>, @@ -168,21 +173,17 @@ impl WriteBackendMethods for LlvmCodegenBackend { ) -> Result<CompiledModule, FatalError> { back::write::codegen(cgcx, diag_handler, module, config) } - fn prepare_thin( - module: ModuleCodegen<Self::Module> - ) -> (String, Self::ThinBuffer) { + fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) { back::lto::prepare_thin(module) } - fn serialize_module( - module: ModuleCodegen<Self::Module> - ) -> (String, Self::ModuleBuffer) { + fn serialize_module(module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer) { (module.name, back::lto::ModuleBuffer::new(module.module_llvm.llmod())) } fn run_lto_pass_manager( cgcx: &CodegenContext<Self>, module: &ModuleCodegen<Self::Module>, config: &ModuleConfig, - thin: bool + thin: bool, ) { back::lto::run_pass_manager(cgcx, module, config, thin) } @@ -213,14 +214,14 @@ impl CodegenBackend for LlvmCodegenBackend { } PrintRequest::CodeModels => { println!("Available code models:"); - for &(name, _) in back::write::CODE_GEN_MODEL_ARGS.iter(){ + for &(name, _) in back::write::CODE_GEN_MODEL_ARGS.iter() { println!(" {}", name); } println!(); } PrintRequest::TlsModels => { println!("Available TLS models:"); - for &(name, _) in back::write::TLS_MODEL_ARGS.iter(){ + for &(name, _) in back::write::TLS_MODEL_ARGS.iter() { println!(" {}", name); } println!(); @@ -260,7 +261,11 @@ impl CodegenBackend for LlvmCodegenBackend { need_metadata_module: bool, ) -> Box<dyn Any> { box rustc_codegen_ssa::base::codegen_crate( - LlvmCodegenBackend(()), tcx, metadata, need_metadata_module) + LlvmCodegenBackend(()), + tcx, + metadata, + need_metadata_module, + ) } fn join_codegen_and_link( @@ -271,23 +276,26 @@ impl CodegenBackend for LlvmCodegenBackend { outputs: &OutputFilenames, ) -> Result<(), ErrorReported> { use rustc::util::common::time; - let (codegen_results, work_products) = - ongoing_codegen.downcast:: - <rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>() - .expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>") - .join(sess); + let (codegen_results, work_products) = ongoing_codegen + .downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>() + .expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>") + .join(sess); if sess.opts.debugging_opts.incremental_info { rustc_codegen_ssa::back::write::dump_incremental_data(&codegen_results); } - time(sess, - "serialize work products", - move || rustc_incremental::save_work_product_index(sess, &dep_graph, work_products)); + time(sess, "serialize work products", move || { + rustc_incremental::save_work_product_index(sess, &dep_graph, work_products) + }); sess.compile_status()?; - if !sess.opts.output_types.keys().any(|&i| i == OutputType::Exe || - i == OutputType::Metadata) { + if !sess + .opts + .output_types + .keys() + .any(|&i| i == OutputType::Exe || i == OutputType::Metadata) + { return Ok(()); } @@ -296,8 +304,8 @@ impl CodegenBackend for LlvmCodegenBackend { time(sess, "linking", || { let _prof_timer = sess.prof.generic_activity("link_crate"); - use rustc_codegen_ssa::back::link::link_binary; use crate::back::archive::LlvmArchiveBuilder; + use rustc_codegen_ssa::back::link::link_binary; let target_cpu = crate::llvm_util::target_cpu(sess); link_binary::<LlvmArchiveBuilder<'_>>( @@ -323,19 +331,15 @@ pub struct ModuleLlvm { tm: &'static mut llvm::TargetMachine, } -unsafe impl Send for ModuleLlvm { } -unsafe impl Sync for ModuleLlvm { } +unsafe impl Send for ModuleLlvm {} +unsafe impl Sync for ModuleLlvm {} impl ModuleLlvm { fn new(tcx: TyCtxt<'_>, mod_name: &str) -> Self { unsafe { let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names()); let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _; - ModuleLlvm { - llmod_raw, - llcx, - tm: create_target_machine(tcx, false), - } + ModuleLlvm { llmod_raw, llcx, tm: create_target_machine(tcx, false) } } } @@ -364,22 +368,16 @@ impl ModuleLlvm { Ok(m) => m, Err(e) => { handler.struct_err(&e).emit(); - return Err(FatalError) + return Err(FatalError); } }; - Ok(ModuleLlvm { - llmod_raw, - llcx, - tm, - }) + Ok(ModuleLlvm { llmod_raw, llcx, tm }) } } fn llmod(&self) -> &llvm::Module { - unsafe { - &*self.llmod_raw - } + unsafe { &*self.llmod_raw } } } |
