1
Fork 0

Use informational target machine for metadata

Since there is nothing to optimise there...
This commit is contained in:
Simonas Kazlauskas 2019-02-20 22:27:00 +02:00
parent 54479c624c
commit 8d4afbe413
5 changed files with 35 additions and 18 deletions

View file

@ -10,9 +10,9 @@ use crate::type_::Type;
use crate::context::{is_pie_binary, get_reloc_model}; use crate::context::{is_pie_binary, get_reloc_model};
use crate::common; use crate::common;
use crate::LlvmCodegenBackend; use crate::LlvmCodegenBackend;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, run_assembler}; use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, run_assembler};
use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::traits::*;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::session::config::{self, OutputType, Passes, Lto}; use rustc::session::config::{self, OutputType, Passes, Lto};
use rustc::session::Session; use rustc::session::Session;
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
@ -82,14 +82,6 @@ pub fn write_output_file(
} }
} }
pub fn create_target_machine(
tcx: TyCtxt<'_, '_, '_>,
find_features: bool,
) -> &'static mut llvm::TargetMachine {
target_machine_factory(tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE), find_features)()
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise() )
}
pub fn create_informational_target_machine( pub fn create_informational_target_machine(
sess: &Session, sess: &Session,
find_features: bool, find_features: bool,
@ -99,6 +91,15 @@ pub fn create_informational_target_machine(
}) })
} }
pub fn create_target_machine(
tcx: TyCtxt<'_, '_, '_>,
find_features: bool,
) -> &'static mut llvm::TargetMachine {
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE), find_features)()
.unwrap_or_else(|err| {
llvm_err(tcx.sess.diagnostic(), &err).raise()
})
}
pub fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm::CodeGenOptSize) pub fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm::CodeGenOptSize)
{ {

View file

@ -13,10 +13,9 @@
//! but one `llvm::Type` corresponds to many `Ty`s; for instance, `tup(int, int, //! but one `llvm::Type` corresponds to many `Ty`s; for instance, `tup(int, int,
//! int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`. //! int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`.
use super::ModuleLlvm; use super::{LlvmCodegenBackend, ModuleLlvm};
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
use rustc_codegen_ssa::base::maybe_create_entry_wrapper; use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
use super::LlvmCodegenBackend;
use crate::llvm; use crate::llvm;
use crate::metadata; use crate::metadata;
@ -163,10 +162,9 @@ pub fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
cgu_name: InternedString) cgu_name: InternedString)
-> (Stats, ModuleCodegen<ModuleLlvm>) -> (Stats, ModuleCodegen<ModuleLlvm>)
{ {
let backend = LlvmCodegenBackend(());
let cgu = tcx.codegen_unit(cgu_name); let cgu = tcx.codegen_unit(cgu_name);
// Instantiate monomorphizations without filling out definitions yet... // Instantiate monomorphizations without filling out definitions yet...
let llvm_module = backend.new_metadata(tcx, &cgu_name.as_str()); let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
let stats = { let stats = {
let cx = CodegenCx::new(tcx, cgu, &llvm_module); let cx = CodegenCx::new(tcx, cgu, &llvm_module);
let mono_items = cx.codegen_unit let mono_items = cx.codegen_unit

View file

@ -154,7 +154,7 @@ pub unsafe fn create_module(
// Ensure the data-layout values hardcoded remain the defaults. // Ensure the data-layout values hardcoded remain the defaults.
if sess.target.target.options.is_builtin { if sess.target.target.options.is_builtin {
let tm = crate::back::write::create_target_machine(tcx, false); let tm = crate::back::write::create_informational_target_machine(&tcx.sess, false);
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm); llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
llvm::LLVMRustDisposeTargetMachine(tm); llvm::LLVMRustDisposeTargetMachine(tm);

View file

@ -23,7 +23,7 @@
#![deny(rust_2018_idioms)] #![deny(rust_2018_idioms)]
#![allow(explicit_outlives_requirements)] #![allow(explicit_outlives_requirements)]
use back::write::create_target_machine; use back::write::{create_target_machine, create_informational_target_machine};
use syntax_pos::symbol::Symbol; use syntax_pos::symbol::Symbol;
extern crate flate2; extern crate flate2;
@ -112,8 +112,9 @@ pub struct LlvmCodegenBackend(());
impl ExtraBackendMethods for LlvmCodegenBackend { impl ExtraBackendMethods for LlvmCodegenBackend {
fn new_metadata(&self, tcx: TyCtxt<'_, '_, '_>, mod_name: &str) -> ModuleLlvm { fn new_metadata(&self, tcx: TyCtxt<'_, '_, '_>, mod_name: &str) -> ModuleLlvm {
ModuleLlvm::new(tcx, mod_name) ModuleLlvm::new_metadata(tcx, mod_name)
} }
fn write_metadata<'b, 'gcx>( fn write_metadata<'b, 'gcx>(
&self, &self,
tcx: TyCtxt<'b, 'gcx, 'gcx>, tcx: TyCtxt<'b, 'gcx, 'gcx>,
@ -363,7 +364,6 @@ impl ModuleLlvm {
unsafe { unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names()); let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _; let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;
ModuleLlvm { ModuleLlvm {
llmod_raw, llmod_raw,
llcx, llcx,
@ -372,6 +372,18 @@ impl ModuleLlvm {
} }
} }
fn new_metadata(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_informational_target_machine(&tcx.sess, false),
}
}
}
fn parse( fn parse(
cgcx: &CodegenContext<LlvmCodegenBackend>, cgcx: &CodegenContext<LlvmCodegenBackend>,
name: &str, name: &str,

View file

@ -1075,7 +1075,13 @@ fn start_executing_work<B: ExtraBackendMethods>(
None None
}; };
let ol = tcx.backend_optimization_level(LOCAL_CRATE); let ol = if tcx.sess.opts.debugging_opts.no_codegen
|| !tcx.sess.opts.output_types.should_codegen() {
// If we know that we wont be doing codegen, create target machines without optimisation.
config::OptLevel::No
} else {
tcx.backend_optimization_level(LOCAL_CRATE)
};
let cgcx = CodegenContext::<B> { let cgcx = CodegenContext::<B> {
backend: backend.clone(), backend: backend.clone(),
crate_types: sess.crate_types.borrow().clone(), crate_types: sess.crate_types.borrow().clone(),