//! 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;
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(());
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>>,
) {
&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 {
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>,
) -> 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)
}
}
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!();
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(
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<'_>>(
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) }
}
}
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 }
}
}