1
Fork 0

Target option to require explicit cpu

Some targets have many different CPUs and no generic CPU that can be
used as a default. For these targets, the user needs to explicitly
specify a CPU through `-C target-cpu=`.

Add an option for targets and an error message if no CPU is set.

This affects the proposed amdgpu and avr targets.
This commit is contained in:
Flakebi 2025-01-02 13:15:21 +01:00
parent bf6f8a4d32
commit 53238c3db6
No known key found for this signature in database
GPG key ID: 38E7ED984D7DCD02
7 changed files with 41 additions and 0 deletions

View file

@ -546,6 +546,7 @@ impl Target {
key!(link_env_remove, list);
key!(asm_args, list);
key!(cpu);
key!(need_explicit_cpu, bool);
key!(features);
key!(dynamic_linking, bool);
key!(direct_access_external_data, Option<bool>);
@ -720,6 +721,7 @@ impl ToJson for Target {
target_option_val!(link_env_remove);
target_option_val!(asm_args);
target_option_val!(cpu);
target_option_val!(need_explicit_cpu);
target_option_val!(features);
target_option_val!(dynamic_linking);
target_option_val!(direct_access_external_data);

View file

@ -2240,6 +2240,9 @@ pub struct TargetOptions {
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
/// to "generic".
pub cpu: StaticCow<str>,
/// Whether a cpu needs to be explicitly set.
/// Set to true if there is no default cpu. Defaults to false.
pub need_explicit_cpu: bool,
/// Default target features to pass to LLVM. These features overwrite
/// `-Ctarget-cpu` but can be overwritten with `-Ctarget-features`.
/// Corresponds to `llc -mattr=$features`.
@ -2676,6 +2679,7 @@ impl Default for TargetOptions {
link_script: None,
asm_args: cvs![],
cpu: "generic".into(),
need_explicit_cpu: false,
features: "".into(),
direct_access_external_data: None,
dynamic_linking: false,