]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/lib.rs
Rollup merge of #67922 - Centril:lowering-cleanup, r=petrochenkov
[rust.git] / src / librustc_codegen_llvm / lib.rs
index 1e1d74cfa9a40b3910f9241fa5a07d5ea57cdb7d..35c71a66756833e5fd5522977cc4b1768f6b85ee 100644 (file)
@@ -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)]
 #![feature(static_nobundle)]
 #![feature(trusted_len)]
 
-use back::write::{create_target_machine, create_informational_target_machine};
-use syntax_pos::symbol::Symbol;
+use back::write::{create_informational_target_machine, create_target_machine};
+use rustc_span::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 back {
 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 @@ fn codegen_allocator<'tcx>(
         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 @@ fn target_machine_factory(
         &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 @@ unsafe fn codegen(
     ) -> 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 @@ fn print(&self, req: PrintRequest, sess: &Session) {
             }
             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 @@ fn codegen_crate<'tcx>(
         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(
@@ -270,34 +275,34 @@ fn join_codegen_and_link(
         dep_graph: &DepGraph,
         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));
+        sess.time("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(());
         }
 
         // Run the linker on any artifacts that resulted from the LLVM run.
         // This should produce either a finished executable or library.
-        time(sess, "linking", || {
-            let _prof_timer = sess.prof.generic_activity("link_crate");
-
-            use rustc_codegen_ssa::back::link::link_binary;
+        sess.time("link_crate", || {
             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 +328,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 +365,16 @@ fn parse(
                 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 }
     }
 }