Use informational target machine for metadata
Since there is nothing to optimise there...
This commit is contained in:
parent
54479c624c
commit
8d4afbe413
5 changed files with 35 additions and 18 deletions
|
@ -10,9 +10,9 @@ use crate::type_::Type;
|
|||
use crate::context::{is_pie_binary, get_reloc_model};
|
||||
use crate::common;
|
||||
use crate::LlvmCodegenBackend;
|
||||
use rustc::hir::def_id::LOCAL_CRATE;
|
||||
use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, run_assembler};
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
use rustc::hir::def_id::LOCAL_CRATE;
|
||||
use rustc::session::config::{self, OutputType, Passes, Lto};
|
||||
use rustc::session::Session;
|
||||
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(
|
||||
sess: &Session,
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -13,10 +13,9 @@
|
|||
//! 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`.
|
||||
|
||||
use super::ModuleLlvm;
|
||||
use super::{LlvmCodegenBackend, ModuleLlvm};
|
||||
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
|
||||
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
|
||||
use super::LlvmCodegenBackend;
|
||||
|
||||
use crate::llvm;
|
||||
use crate::metadata;
|
||||
|
@ -163,10 +162,9 @@ pub fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
cgu_name: InternedString)
|
||||
-> (Stats, ModuleCodegen<ModuleLlvm>)
|
||||
{
|
||||
let backend = LlvmCodegenBackend(());
|
||||
let cgu = tcx.codegen_unit(cgu_name);
|
||||
// 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 cx = CodegenCx::new(tcx, cgu, &llvm_module);
|
||||
let mono_items = cx.codegen_unit
|
||||
|
|
|
@ -154,7 +154,7 @@ pub unsafe fn create_module(
|
|||
|
||||
// Ensure the data-layout values hardcoded remain the defaults.
|
||||
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::LLVMRustDisposeTargetMachine(tm);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#![deny(rust_2018_idioms)]
|
||||
#![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;
|
||||
|
||||
extern crate flate2;
|
||||
|
@ -112,8 +112,9 @@ pub struct LlvmCodegenBackend(());
|
|||
|
||||
impl ExtraBackendMethods for LlvmCodegenBackend {
|
||||
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>(
|
||||
&self,
|
||||
tcx: TyCtxt<'b, 'gcx, 'gcx>,
|
||||
|
@ -363,7 +364,6 @@ impl ModuleLlvm {
|
|||
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,
|
||||
|
@ -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(
|
||||
cgcx: &CodegenContext<LlvmCodegenBackend>,
|
||||
name: &str,
|
||||
|
|
|
@ -1075,7 +1075,13 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
|||
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 won’t be doing codegen, create target machines without optimisation.
|
||||
config::OptLevel::No
|
||||
} else {
|
||||
tcx.backend_optimization_level(LOCAL_CRATE)
|
||||
};
|
||||
let cgcx = CodegenContext::<B> {
|
||||
backend: backend.clone(),
|
||||
crate_types: sess.crate_types.borrow().clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue