1
Fork 0

Collapse all uses of target.options.foo into target.foo

with an eye on merging `TargetOptions` into `Target`.

`TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
This commit is contained in:
Vadim Petrochenkov 2020-11-08 14:27:51 +03:00
parent 87a0997ef9
commit bf66988aa1
48 changed files with 235 additions and 260 deletions

View file

@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
let name = format!("__rust_{}", method.name);
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);
if tcx.sess.target.options.default_hidden_visibility {
if tcx.sess.target.default_hidden_visibility {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
if tcx.sess.must_emit_unwind_tables() {
@ -98,7 +98,7 @@ pub(crate) unsafe fn codegen(
// -> ! DIFlagNoReturn
llvm::Attribute::NoReturn.apply_llfn(llvm::AttributePlace::Function, llfn);
if tcx.sess.target.options.default_hidden_visibility {
if tcx.sess.target.default_hidden_visibility {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
if tcx.sess.must_emit_unwind_tables() {

View file

@ -90,8 +90,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
// The function name varies on platforms.
// See test/CodeGen/mcount.c in clang.
let mcount_name =
CString::new(cx.sess().target.options.target_mcount.as_str().as_bytes()).unwrap();
let mcount_name = CString::new(cx.sess().target.target_mcount.as_str().as_bytes()).unwrap();
llvm::AddFunctionAttrStringValue(
llfn,
@ -105,7 +104,7 @@ fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
// Only use stack probes if the target specification indicates that we
// should be using stack probes
if !cx.sess().target.options.stack_probes {
if !cx.sess().target.stack_probes {
return;
}
@ -174,7 +173,6 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
.split(',')
.filter(|f| !RUSTC_SPECIFIC_FEATURES.iter().any(|s| f.contains(s)));
sess.target
.options
.features
.split(',')
.chain(cmdline)

View file

@ -206,7 +206,7 @@ impl<'a> LlvmArchiveBuilder<'a> {
}
fn llvm_archive_kind(&self) -> Result<ArchiveKind, &str> {
let kind = &*self.config.sess.target.options.archive_format;
let kind = &*self.config.sess.target.archive_format;
kind.parse().map_err(|_| kind)
}

View file

@ -129,13 +129,13 @@ pub fn target_machine_factory(
let use_softfp = sess.opts.cg.soft_float;
let ffunction_sections =
sess.opts.debugging_opts.function_sections.unwrap_or(sess.target.options.function_sections);
sess.opts.debugging_opts.function_sections.unwrap_or(sess.target.function_sections);
let fdata_sections = ffunction_sections;
let code_model = to_llvm_code_model(sess.code_model());
let features = attributes::llvm_target_features(sess).collect::<Vec<_>>();
let mut singlethread = sess.target.options.singlethread;
let mut singlethread = sess.target.singlethread;
// On the wasm target once the `atomics` feature is enabled that means that
// we're no longer single-threaded, or otherwise we don't want LLVM to
@ -151,22 +151,16 @@ pub fn target_machine_factory(
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
let features = features.join(",");
let features = CString::new(features).unwrap();
let abi = SmallCStr::new(&sess.target.options.llvm_abiname);
let trap_unreachable = sess.target.options.trap_unreachable;
let abi = SmallCStr::new(&sess.target.llvm_abiname);
let trap_unreachable = sess.target.trap_unreachable;
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;
let asm_comments = sess.asm_comments();
let relax_elf_relocations = sess
.opts
.debugging_opts
.relax_elf_relocations
.unwrap_or(sess.target.options.relax_elf_relocations);
let relax_elf_relocations =
sess.opts.debugging_opts.relax_elf_relocations.unwrap_or(sess.target.relax_elf_relocations);
let use_init_array = !sess
.opts
.debugging_opts
.use_ctors_section
.unwrap_or(sess.target.options.use_ctors_section);
let use_init_array =
!sess.opts.debugging_opts.use_ctors_section.unwrap_or(sess.target.use_ctors_section);
Arc::new(move || {
let tm = unsafe {

View file

@ -91,7 +91,7 @@ fn set_global_alignment(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align: Alig
// The target may require greater alignment for globals than the type does.
// Note: GCC and Clang also allow `__attribute__((aligned))` on variables,
// which can force it to be smaller. Rust doesn't support this yet.
if let Some(min) = cx.sess().target.options.min_global_align {
if let Some(min) = cx.sess().target.min_global_align {
match Align::from_bits(min) {
Ok(min) => align = align.max(min),
Err(err) => {
@ -283,7 +283,7 @@ impl CodegenCx<'ll, 'tcx> {
// argument validation.
debug_assert!(
!(self.tcx.sess.opts.cg.linker_plugin_lto.enabled()
&& self.tcx.sess.target.options.is_like_windows
&& self.tcx.sess.target.is_like_windows
&& self.tcx.sess.opts.cg.prefer_dynamic)
);
@ -435,7 +435,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
// will use load-unaligned instructions instead, and thus avoiding the crash.
//
// We could remove this hack whenever we decide to drop macOS 10.10 support.
if self.tcx.sess.target.options.is_like_osx {
if self.tcx.sess.target.is_like_osx {
// The `inspect` method is okay here because we checked relocations, and
// because we are doing this access to inspect the final interpreter state
// (not as part of the interpreter execution).

View file

@ -129,7 +129,7 @@ pub unsafe fn create_module(
}
// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.options.is_builtin {
if sess.target.is_builtin {
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
llvm::LLVMRustDisposeTargetMachine(tm);
@ -190,7 +190,7 @@ pub unsafe fn create_module(
}
// Control Flow Guard is currently only supported by the MSVC linker on Windows.
if sess.target.options.is_like_msvc {
if sess.target.is_like_msvc {
match sess.opts.cg.control_flow_guard {
CFGuard::Disabled => {}
CFGuard::NoChecks => {
@ -265,7 +265,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
// linker will take care of everything. Fixing this problem will likely
// require adding a few attributes to Rust itself (feature gated at the
// start) and then strongly recommending static linkage on Windows!
let use_dll_storage_attrs = tcx.sess.target.options.is_like_windows;
let use_dll_storage_attrs = tcx.sess.target.is_like_windows;
let check_overflow = tcx.sess.overflow_checks();
@ -839,7 +839,7 @@ impl CodegenCx<'b, 'tcx> {
return eh_catch_typeinfo;
}
let tcx = self.tcx;
assert!(self.sess().target.options.is_like_emscripten);
assert!(self.sess().target.is_like_emscripten);
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
Some(def_id) => self.get_static(def_id),
_ => {

View file

@ -67,5 +67,5 @@ pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
!omit_gdb_pretty_printer_section
&& cx.sess().opts.debuginfo != DebugInfo::None
&& cx.sess().target.options.emit_debug_gdb_scripts
&& cx.sess().target.emit_debug_gdb_scripts
}

View file

@ -870,7 +870,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
// When targeting MSVC, emit MSVC style type names for compatibility with
// .natvis visualizers (and perhaps other existing native debuggers?)
let msvc_like_names = cx.tcx.sess.target.options.is_like_msvc;
let msvc_like_names = cx.tcx.sess.target.is_like_msvc;
let (name, encoding) = match t.kind() {
ty::Never => ("!", DW_ATE_unsigned),
@ -981,7 +981,7 @@ pub fn compile_unit_metadata(
// if multiple object files with the same `DW_AT_name` are linked together.
// As a workaround we generate unique names for each object file. Those do
// not correspond to an actual source file but that should be harmless.
if tcx.sess.target.options.is_like_osx {
if tcx.sess.target.is_like_osx {
name_in_debuginfo.push("@");
name_in_debuginfo.push(codegen_unit_name);
}
@ -1397,7 +1397,7 @@ fn prepare_union_metadata(
/// on MSVC we have to use the fallback mode, because LLVM doesn't
/// lower variant parts to PDB.
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
cx.sess().target.options.is_like_msvc
cx.sess().target.is_like_msvc
}
// FIXME(eddyb) maybe precompute this? Right now it's computed once

View file

@ -122,12 +122,12 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
// for macOS to understand. For more info see #11352
// This can be overridden using --llvm-opts -dwarf-version,N.
// Android has the same issue (#22398)
if let Some(version) = cx.sess().target.options.dwarf_version {
if let Some(version) = cx.sess().target.dwarf_version {
llvm::LLVMRustAddModuleFlag(cx.llmod, "Dwarf Version\0".as_ptr().cast(), version)
}
// Indicate that we want CodeView debug information on MSVC
if cx.sess().target.options.is_like_msvc {
if cx.sess().target.is_like_msvc {
llvm::LLVMRustAddModuleFlag(cx.llmod, "CodeView\0".as_ptr().cast(), 1)
}
@ -251,7 +251,7 @@ impl CodegenCx<'ll, '_> {
// For MSVC, omit the column number.
// Otherwise, emit it. This mimics clang behaviour.
// See discussion in https://github.com/rust-lang/rust/issues/42921
if self.sess().target.options.is_like_msvc {
if self.sess().target.is_like_msvc {
DebugLoc { file, line, col: None }
} else {
DebugLoc { file, line, col }
@ -387,7 +387,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
});
// Arguments types
if cx.sess().target.options.is_like_msvc {
if cx.sess().target.is_like_msvc {
// FIXME(#42800):
// There is a bug in MSDIA that leads to a crash when it encounters
// a fixed-size array of `u8` or something zero-sized in a

View file

@ -42,7 +42,7 @@ fn declare_raw_fn(
// be merged.
llvm::SetUnnamedAddress(llfn, llvm::UnnamedAddr::Global);
if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.options.disable_redzone) {
if cx.tcx.sess.opts.cg.no_redzone.unwrap_or(cx.tcx.sess.target.disable_redzone) {
llvm::Attribute::NoRedZone.apply_llfn(Function, llfn);
}

View file

@ -367,7 +367,7 @@ fn try_intrinsic(
bx.store(bx.const_i32(0), dest, ret_align);
} else if wants_msvc_seh(bx.sess()) {
codegen_msvc_try(bx, try_func, data, catch_func, dest);
} else if bx.sess().target.options.is_like_emscripten {
} else if bx.sess().target.is_like_emscripten {
codegen_emcc_try(bx, try_func, data, catch_func, dest);
} else {
codegen_gnu_try(bx, try_func, data, catch_func, dest);

View file

@ -46,7 +46,7 @@ fn require_inited() {
}
unsafe fn configure_llvm(sess: &Session) {
let n_args = sess.opts.cg.llvm_args.len() + sess.target.options.llvm_args.len();
let n_args = sess.opts.cg.llvm_args.len() + sess.target.llvm_args.len();
let mut llvm_c_strs = Vec::with_capacity(n_args + 1);
let mut llvm_args = Vec::with_capacity(n_args + 1);
@ -57,7 +57,7 @@ unsafe fn configure_llvm(sess: &Session) {
}
let cg_opts = sess.opts.cg.llvm_args.iter();
let tg_opts = sess.target.options.llvm_args.iter();
let tg_opts = sess.target.llvm_args.iter();
let sess_args = cg_opts.chain(tg_opts);
let user_specified_args: FxHashSet<_> =
@ -84,12 +84,7 @@ unsafe fn configure_llvm(sess: &Session) {
if !sess.opts.debugging_opts.no_generate_arange_section {
add("-generate-arange-section", false);
}
match sess
.opts
.debugging_opts
.merge_functions
.unwrap_or(sess.target.options.merge_functions)
{
match sess.opts.debugging_opts.merge_functions.unwrap_or(sess.target.merge_functions) {
MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
add("-mergefunc-use-aliases", false);
@ -215,7 +210,7 @@ fn handle_native(name: &str) -> &str {
pub fn target_cpu(sess: &Session) -> &str {
let name = match sess.opts.cg.target_cpu {
Some(ref s) => &**s,
None => &*sess.target.options.cpu,
None => &*sess.target.cpu,
};
handle_native(name)

View file

@ -104,7 +104,7 @@ pub fn metadata_section_name(target: &Target) -> &'static str {
// As a result, we choose a slightly shorter name! As to why
// `.note.rustc` works on MinGW, that's another good question...
if target.options.is_like_osx { "__DATA,.rustc" } else { ".rustc" }
if target.is_like_osx { "__DATA,.rustc" } else { ".rustc" }
}
fn read_metadata_section_name(_target: &Target) -> &'static str {

View file

@ -175,22 +175,22 @@ pub(super) fn emit_va_arg(
let arch = &bx.cx.tcx.sess.target.arch;
match &**arch {
// Windows x86
"x86" if target.options.is_like_windows => {
"x86" if target.is_like_windows => {
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), false)
}
// Generic x86
"x86" => emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), true),
// Windows AArch64
"aarch64" if target.options.is_like_windows => {
"aarch64" if target.is_like_windows => {
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), false)
}
// macOS / iOS AArch64
"aarch64" if target.options.is_like_osx => {
"aarch64" if target.is_like_osx => {
emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), true)
}
"aarch64" => emit_aapcs_va_arg(bx, addr, target_ty),
// Windows x86_64
"x86_64" if target.options.is_like_windows => {
"x86_64" if target.is_like_windows => {
let target_ty_size = bx.cx.size_of(target_ty).bytes();
let indirect: bool = target_ty_size > 8 || !target_ty_size.is_power_of_two();
emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false)