Combine ModuleConfig::embed_bitcode{,_marker}.

Because the `(true, true)` combination isn't valid.
This commit is contained in:
Nicholas Nethercote 2020-03-20 12:34:39 +11:00
parent d156bf658f
commit 47c8f3f56b
2 changed files with 25 additions and 17 deletions

View File

@ -18,7 +18,7 @@ use rustc::bug;
use rustc::session::config::{self, Lto, OutputType, Passes, Sanitizer, SwitchWithOptPath};
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc_codegen_ssa::back::write::{run_assembler, CodegenContext, ModuleConfig};
use rustc_codegen_ssa::back::write::{run_assembler, CodegenContext, EmbedBitcode, ModuleConfig};
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen, RLIB_BYTECODE_EXTENSION};
use rustc_data_structures::small_c_str::SmallCStr;
@ -662,7 +662,7 @@ pub(crate) unsafe fn codegen(
}
}
if config.embed_bitcode {
if config.embed_bitcode == EmbedBitcode::Full {
let _timer = cgcx.prof.generic_activity_with_arg(
"LLVM_module_codegen_embed_bitcode",
&module.name[..],
@ -682,7 +682,7 @@ pub(crate) unsafe fn codegen(
diag_handler.err(&msg);
}
}
} else if config.embed_bitcode_marker {
} else if config.embed_bitcode == EmbedBitcode::Marker {
embed_bitcode(cgcx, llcx, llmod, None);
}

View File

@ -51,6 +51,14 @@ use std::thread;
const PRE_LTO_BC_EXT: &str = "pre-lto.bc";
/// The kind of bitcode to embed in object files.
#[derive(PartialEq)]
pub enum EmbedBitcode {
None,
Marker,
Full,
}
/// Module-specific configuration for `optimize_and_codegen`.
pub struct ModuleConfig {
/// Names of additional optimization passes to run.
@ -93,8 +101,7 @@ pub struct ModuleConfig {
// emscripten's ecc compiler, when used as the linker.
pub obj_is_bitcode: bool,
pub no_integrated_as: bool,
pub embed_bitcode: bool,
pub embed_bitcode_marker: bool,
pub embed_bitcode: EmbedBitcode,
}
impl ModuleConfig {
@ -119,8 +126,7 @@ impl ModuleConfig {
emit_asm: false,
emit_obj: false,
obj_is_bitcode: false,
embed_bitcode: false,
embed_bitcode_marker: false,
embed_bitcode: EmbedBitcode::None,
no_integrated_as: false,
verify_llvm_ir: false,
@ -143,16 +149,15 @@ impl ModuleConfig {
self.new_llvm_pass_manager = sess.opts.debugging_opts.new_llvm_pass_manager;
self.obj_is_bitcode =
sess.target.target.options.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled();
let embed_bitcode =
sess.target.target.options.embed_bitcode || sess.opts.debugging_opts.embed_bitcode;
if embed_bitcode {
match sess.opts.optimize {
config::OptLevel::No | config::OptLevel::Less => {
self.embed_bitcode_marker = embed_bitcode;
self.embed_bitcode =
if sess.target.target.options.embed_bitcode || sess.opts.debugging_opts.embed_bitcode {
match sess.opts.optimize {
config::OptLevel::No | config::OptLevel::Less => EmbedBitcode::Marker,
_ => EmbedBitcode::Full,
}
_ => self.embed_bitcode = embed_bitcode,
}
}
} else {
EmbedBitcode::None
};
// Copy what clang does by turning on loop vectorization at O2 and
// slp vectorization at O3. Otherwise configure other optimization aspects
@ -188,7 +193,10 @@ impl ModuleConfig {
}
pub fn bitcode_needed(&self) -> bool {
self.emit_bc || self.obj_is_bitcode || self.emit_bc_compressed || self.embed_bitcode
self.emit_bc
|| self.obj_is_bitcode
|| self.emit_bc_compressed
|| self.embed_bitcode == EmbedBitcode::Full
}
}