add llvm_floatabi field to target spec that controls FloatABIType
This commit is contained in:
parent
fff026c8e5
commit
a0dbb37ebd
3 changed files with 67 additions and 4 deletions
|
@ -26,7 +26,7 @@ use rustc_session::config::{
|
||||||
self, Lto, OutputType, Passes, RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath,
|
self, Lto, OutputType, Passes, RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath,
|
||||||
};
|
};
|
||||||
use rustc_span::{BytePos, InnerSpan, Pos, SpanData, SyntaxContext, sym};
|
use rustc_span::{BytePos, InnerSpan, Pos, SpanData, SyntaxContext, sym};
|
||||||
use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
|
use rustc_target::spec::{CodeModel, FloatAbi, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::back::lto::ThinBuffer;
|
use crate::back::lto::ThinBuffer;
|
||||||
|
@ -40,7 +40,7 @@ use crate::errors::{
|
||||||
WithLlvmError, WriteBytecode,
|
WithLlvmError, WriteBytecode,
|
||||||
};
|
};
|
||||||
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
|
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
|
||||||
use crate::llvm::{self, DiagnosticInfo, FloatAbi, PassManager};
|
use crate::llvm::{self, DiagnosticInfo, PassManager};
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};
|
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};
|
||||||
|
|
||||||
|
@ -181,6 +181,14 @@ pub(crate) fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeMod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_llvm_float_abi(float_abi: Option<FloatAbi>) -> llvm::FloatAbi {
|
||||||
|
match float_abi {
|
||||||
|
None => llvm::FloatAbi::Default,
|
||||||
|
Some(FloatAbi::Soft) => llvm::FloatAbi::Soft,
|
||||||
|
Some(FloatAbi::Hard) => llvm::FloatAbi::Hard,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn target_machine_factory(
|
pub(crate) fn target_machine_factory(
|
||||||
sess: &Session,
|
sess: &Session,
|
||||||
optlvl: config::OptLevel,
|
optlvl: config::OptLevel,
|
||||||
|
@ -190,11 +198,11 @@ pub(crate) fn target_machine_factory(
|
||||||
|
|
||||||
let (opt_level, _) = to_llvm_opt_settings(optlvl);
|
let (opt_level, _) = to_llvm_opt_settings(optlvl);
|
||||||
let float_abi = if sess.target.arch == "arm" && sess.opts.cg.soft_float {
|
let float_abi = if sess.target.arch == "arm" && sess.opts.cg.soft_float {
|
||||||
FloatAbi::Soft
|
llvm::FloatAbi::Soft
|
||||||
} else {
|
} else {
|
||||||
// `validate_commandline_args_with_session_available` has already warned about this being
|
// `validate_commandline_args_with_session_available` has already warned about this being
|
||||||
// ignored. Let's make sure LLVM doesn't suddenly start using this flag on more targets.
|
// ignored. Let's make sure LLVM doesn't suddenly start using this flag on more targets.
|
||||||
FloatAbi::Default
|
to_llvm_float_abi(sess.target.llvm_floatabi)
|
||||||
};
|
};
|
||||||
|
|
||||||
let ffunction_sections =
|
let ffunction_sections =
|
||||||
|
|
|
@ -116,6 +116,18 @@ impl Target {
|
||||||
Some(Ok(()))
|
Some(Ok(()))
|
||||||
})).unwrap_or(Ok(()))
|
})).unwrap_or(Ok(()))
|
||||||
} );
|
} );
|
||||||
|
($key_name:ident, FloatAbi) => ( {
|
||||||
|
let name = (stringify!($key_name)).replace("_", "-");
|
||||||
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
||||||
|
match s.parse::<super::FloatAbi>() {
|
||||||
|
Ok(float_abi) => base.$key_name = Some(float_abi),
|
||||||
|
_ => return Some(Err(format!("'{}' is not a valid value for \
|
||||||
|
llvm-floatabi. Use 'soft' or 'hard'.",
|
||||||
|
s))),
|
||||||
|
}
|
||||||
|
Some(Ok(()))
|
||||||
|
})).unwrap_or(Ok(()))
|
||||||
|
} );
|
||||||
($key_name:ident, RelocModel) => ( {
|
($key_name:ident, RelocModel) => ( {
|
||||||
let name = (stringify!($key_name)).replace("_", "-");
|
let name = (stringify!($key_name)).replace("_", "-");
|
||||||
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
obj.remove(&name).and_then(|o| o.as_str().and_then(|s| {
|
||||||
|
@ -598,6 +610,7 @@ impl Target {
|
||||||
key!(mcount = "target-mcount");
|
key!(mcount = "target-mcount");
|
||||||
key!(llvm_mcount_intrinsic, optional);
|
key!(llvm_mcount_intrinsic, optional);
|
||||||
key!(llvm_abiname);
|
key!(llvm_abiname);
|
||||||
|
key!(llvm_floatabi, FloatAbi)?;
|
||||||
key!(relax_elf_relocations, bool);
|
key!(relax_elf_relocations, bool);
|
||||||
key!(llvm_args, list);
|
key!(llvm_args, list);
|
||||||
key!(use_ctors_section, bool);
|
key!(use_ctors_section, bool);
|
||||||
|
@ -772,6 +785,7 @@ impl ToJson for Target {
|
||||||
target_option_val!(mcount, "target-mcount");
|
target_option_val!(mcount, "target-mcount");
|
||||||
target_option_val!(llvm_mcount_intrinsic);
|
target_option_val!(llvm_mcount_intrinsic);
|
||||||
target_option_val!(llvm_abiname);
|
target_option_val!(llvm_abiname);
|
||||||
|
target_option_val!(llvm_floatabi);
|
||||||
target_option_val!(relax_elf_relocations);
|
target_option_val!(relax_elf_relocations);
|
||||||
target_option_val!(llvm_args);
|
target_option_val!(llvm_args);
|
||||||
target_option_val!(use_ctors_section);
|
target_option_val!(use_ctors_section);
|
||||||
|
|
|
@ -1085,6 +1085,35 @@ impl ToJson for CodeModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The float ABI setting to be configured in the LLVM target machine.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
||||||
|
pub enum FloatAbi {
|
||||||
|
Soft,
|
||||||
|
Hard,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for FloatAbi {
|
||||||
|
type Err = ();
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<FloatAbi, ()> {
|
||||||
|
Ok(match s {
|
||||||
|
"soft" => FloatAbi::Soft,
|
||||||
|
"hard" => FloatAbi::Hard,
|
||||||
|
_ => return Err(()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToJson for FloatAbi {
|
||||||
|
fn to_json(&self) -> Json {
|
||||||
|
match *self {
|
||||||
|
FloatAbi::Soft => "soft",
|
||||||
|
FloatAbi::Hard => "hard",
|
||||||
|
}
|
||||||
|
.to_json()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
|
||||||
pub enum TlsModel {
|
pub enum TlsModel {
|
||||||
GeneralDynamic,
|
GeneralDynamic,
|
||||||
|
@ -2150,6 +2179,8 @@ pub struct TargetOptions {
|
||||||
pub env: StaticCow<str>,
|
pub env: StaticCow<str>,
|
||||||
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
|
/// ABI name to distinguish multiple ABIs on the same OS and architecture. For instance, `"eabi"`
|
||||||
/// or `"eabihf"`. Defaults to "".
|
/// or `"eabihf"`. Defaults to "".
|
||||||
|
/// This field is *not* forwarded directly to LLVM; its primary purpose is `cfg(target_abi)`.
|
||||||
|
/// However, parts of the backend do check this field for specific values to enable special behavior.
|
||||||
pub abi: StaticCow<str>,
|
pub abi: StaticCow<str>,
|
||||||
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
|
/// Vendor name to use for conditional compilation (`target_vendor`). Defaults to "unknown".
|
||||||
pub vendor: StaticCow<str>,
|
pub vendor: StaticCow<str>,
|
||||||
|
@ -2446,8 +2477,17 @@ pub struct TargetOptions {
|
||||||
pub llvm_mcount_intrinsic: Option<StaticCow<str>>,
|
pub llvm_mcount_intrinsic: Option<StaticCow<str>>,
|
||||||
|
|
||||||
/// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers
|
/// LLVM ABI name, corresponds to the '-mabi' parameter available in multilib C compilers
|
||||||
|
/// and the `-target-abi` flag in llc. In the LLVM API this is `MCOptions.ABIName`.
|
||||||
pub llvm_abiname: StaticCow<str>,
|
pub llvm_abiname: StaticCow<str>,
|
||||||
|
|
||||||
|
/// Control the float ABI to use, for architectures that support it. The only architecture we
|
||||||
|
/// currently use this for is ARM. Corresponds to the `-float-abi` flag in llc. In the LLVM API
|
||||||
|
/// this is `FloatABIType`. (clang's `-mfloat-abi` is similar but more complicated since it
|
||||||
|
/// can also affect the `soft-float` target feature.)
|
||||||
|
///
|
||||||
|
/// If not provided, LLVM will infer the float ABI from the target triple (`llvm_target`).
|
||||||
|
pub llvm_floatabi: Option<FloatAbi>,
|
||||||
|
|
||||||
/// Whether or not RelaxElfRelocation flag will be passed to the linker
|
/// Whether or not RelaxElfRelocation flag will be passed to the linker
|
||||||
pub relax_elf_relocations: bool,
|
pub relax_elf_relocations: bool,
|
||||||
|
|
||||||
|
@ -2719,6 +2759,7 @@ impl Default for TargetOptions {
|
||||||
mcount: "mcount".into(),
|
mcount: "mcount".into(),
|
||||||
llvm_mcount_intrinsic: None,
|
llvm_mcount_intrinsic: None,
|
||||||
llvm_abiname: "".into(),
|
llvm_abiname: "".into(),
|
||||||
|
llvm_floatabi: None,
|
||||||
relax_elf_relocations: false,
|
relax_elf_relocations: false,
|
||||||
llvm_args: cvs![],
|
llvm_args: cvs![],
|
||||||
use_ctors_section: false,
|
use_ctors_section: false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue