Skip to content

Commit

Permalink
Rollup merge of rust-lang#58605 - nagisa:fix-the-metadata, r=michaelw…
Browse files Browse the repository at this point in the history
…oerister

Use informational target machine for metadata

Since there is nothing to optimise there...

Should fix rust-lang#58323 but haven’t tested locally.

r? @michaelwoerister
  • Loading branch information
pietroalbini committed Mar 1, 2019
2 parents 7b4f8f9 + d89c2f6 commit 059121b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
10 changes: 0 additions & 10 deletions src/librustc_codegen_llvm/back/write.rs
Expand Up @@ -13,10 +13,8 @@ use crate::common;
use crate::LlvmCodegenBackend;
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;
use rustc_codegen_ssa::{ModuleCodegen, CompiledModule};
use rustc::util::common::time_ext;
use rustc_fs_util::{path_to_c_string, link_or_copy};
Expand Down Expand Up @@ -82,14 +80,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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_codegen_llvm/lib.rs
Expand Up @@ -24,7 +24,7 @@
#![deny(rust_2018_idioms)]
#![allow(explicit_outlives_requirements)]

use back::write::create_target_machine;
use back::write::create_informational_target_machine;
use syntax_pos::symbol::Symbol;

extern crate flate2;
Expand Down Expand Up @@ -114,8 +114,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>,
Expand Down Expand Up @@ -366,15 +367,14 @@ unsafe impl Send for ModuleLlvm { }
unsafe impl Sync for ModuleLlvm { }

impl ModuleLlvm {
fn new(tcx: TyCtxt<'_, '_, '_>, mod_name: &str) -> Self {
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_target_machine(tcx, false),
tm: create_informational_target_machine(&tcx.sess, false),
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_codegen_ssa/back/write.rs
Expand Up @@ -1022,7 +1022,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(),
Expand Down

0 comments on commit 059121b

Please sign in to comment.