Rollup merge of #136608 - kulst:ptx_target_features, r=bjorn3
Pass through of target features to llvm-bitcode-linker and handling them When using the llvm-bitcode-linker (`linker-flavor=llbc`) target-features are not passed through and are not handled by it. The llvm-bitcode-linker is mainly used as a self contained linker to link llvm bitcode for the nvptx64 target. It uses `llvm-link`, `opt` and `llc` internally. To produce a `.ptx` file of a specific ptx-version it is necessary to pass the version to llc with the `--mattr` option. Without explicitly setting it, the emitted `.ptx`-version is the minimum supported version of the `--target-cpu`. I would like to be able to explicitly set the ptx version as [some llvm problems only occur in earlier `.ptx`-versions](https://github.com/llvm/llvm-project/issues/112998). Therefore this pull request adds support for passing target features to llvm-bitcode-linker and handling them. I was not quite sure if adding these features to `rustc_target/src/target_features.rs` is necessary or not. If so I will gladly add these. r? ``@kjetilkjeka``
This commit is contained in:
commit
6d74563b20
5 changed files with 26 additions and 2 deletions
|
@ -2519,6 +2519,12 @@ fn add_order_independent_options(
|
||||||
"--target-cpu",
|
"--target-cpu",
|
||||||
&codegen_results.crate_info.target_cpu,
|
&codegen_results.crate_info.target_cpu,
|
||||||
]);
|
]);
|
||||||
|
if codegen_results.crate_info.target_features.len() > 0 {
|
||||||
|
cmd.link_arg(&format!(
|
||||||
|
"--target-feature={}",
|
||||||
|
&codegen_results.crate_info.target_features.join(",")
|
||||||
|
));
|
||||||
|
}
|
||||||
} else if flavor == LinkerFlavor::Ptx {
|
} else if flavor == LinkerFlavor::Ptx {
|
||||||
cmd.link_args(&["--fallback-arch", &codegen_results.crate_info.target_cpu]);
|
cmd.link_args(&["--fallback-arch", &codegen_results.crate_info.target_cpu]);
|
||||||
} else if flavor == LinkerFlavor::Bpf {
|
} else if flavor == LinkerFlavor::Bpf {
|
||||||
|
|
|
@ -915,6 +915,7 @@ impl CrateInfo {
|
||||||
let n_crates = crates.len();
|
let n_crates = crates.len();
|
||||||
let mut info = CrateInfo {
|
let mut info = CrateInfo {
|
||||||
target_cpu,
|
target_cpu,
|
||||||
|
target_features: tcx.global_backend_features(()).clone(),
|
||||||
crate_types,
|
crate_types,
|
||||||
exported_symbols,
|
exported_symbols,
|
||||||
linked_symbols,
|
linked_symbols,
|
||||||
|
|
|
@ -190,6 +190,7 @@ impl From<&cstore::NativeLib> for NativeLib {
|
||||||
#[derive(Debug, Encodable, Decodable)]
|
#[derive(Debug, Encodable, Decodable)]
|
||||||
pub struct CrateInfo {
|
pub struct CrateInfo {
|
||||||
pub target_cpu: String,
|
pub target_cpu: String,
|
||||||
|
pub target_features: Vec<String>,
|
||||||
pub crate_types: Vec<CrateType>,
|
pub crate_types: Vec<CrateType>,
|
||||||
pub exported_symbols: UnordMap<CrateType, Vec<String>>,
|
pub exported_symbols: UnordMap<CrateType, Vec<String>>,
|
||||||
pub linked_symbols: FxIndexMap<CrateType, Vec<(String, SymbolExportKind)>>,
|
pub linked_symbols: FxIndexMap<CrateType, Vec<(String, SymbolExportKind)>>,
|
||||||
|
@ -230,6 +231,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
crate::base::provide(providers);
|
crate::base::provide(providers);
|
||||||
crate::target_features::provide(providers);
|
crate::target_features::provide(providers);
|
||||||
crate::codegen_attrs::provide(providers);
|
crate::codegen_attrs::provide(providers);
|
||||||
|
providers.queries.global_backend_features = |_tcx: TyCtxt<'_>, ()| vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the given filename ends with the `.rcgu.o` extension that `rustc`
|
/// Checks if the given filename ends with the `.rcgu.o` extension that `rustc`
|
||||||
|
|
|
@ -27,6 +27,10 @@ pub struct Args {
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
target_cpu: Option<String>,
|
target_cpu: Option<String>,
|
||||||
|
|
||||||
|
/// The target features
|
||||||
|
#[arg(long)]
|
||||||
|
target_feature: Option<String>,
|
||||||
|
|
||||||
/// Write output to the filename
|
/// Write output to the filename
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
output: PathBuf,
|
output: PathBuf,
|
||||||
|
@ -49,7 +53,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let mut linker = Session::new(args.target, args.target_cpu, args.output);
|
let mut linker = Session::new(args.target, args.target_cpu, args.target_feature, args.output);
|
||||||
|
|
||||||
linker.add_exported_symbols(args.export_symbol);
|
linker.add_exported_symbols(args.export_symbol);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{Optimization, Target};
|
||||||
pub struct Session {
|
pub struct Session {
|
||||||
target: Target,
|
target: Target,
|
||||||
cpu: Option<String>,
|
cpu: Option<String>,
|
||||||
|
feature: Option<String>,
|
||||||
symbols: Vec<String>,
|
symbols: Vec<String>,
|
||||||
|
|
||||||
/// A file that `llvm-link` supports, like a bitcode file or an archive.
|
/// A file that `llvm-link` supports, like a bitcode file or an archive.
|
||||||
|
@ -21,7 +22,12 @@ pub struct Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub fn new(target: crate::Target, cpu: Option<String>, out_path: PathBuf) -> Self {
|
pub fn new(
|
||||||
|
target: crate::Target,
|
||||||
|
cpu: Option<String>,
|
||||||
|
feature: Option<String>,
|
||||||
|
out_path: PathBuf,
|
||||||
|
) -> Self {
|
||||||
let link_path = out_path.with_extension("o");
|
let link_path = out_path.with_extension("o");
|
||||||
let opt_path = out_path.with_extension("optimized.o");
|
let opt_path = out_path.with_extension("optimized.o");
|
||||||
let sym_path = out_path.with_extension("symbols.txt");
|
let sym_path = out_path.with_extension("symbols.txt");
|
||||||
|
@ -29,6 +35,7 @@ impl Session {
|
||||||
Session {
|
Session {
|
||||||
target,
|
target,
|
||||||
cpu,
|
cpu,
|
||||||
|
feature,
|
||||||
symbols: Vec::new(),
|
symbols: Vec::new(),
|
||||||
files: Vec::new(),
|
files: Vec::new(),
|
||||||
link_path,
|
link_path,
|
||||||
|
@ -134,6 +141,10 @@ impl Session {
|
||||||
lcc_command.arg("--mcpu").arg(mcpu);
|
lcc_command.arg("--mcpu").arg(mcpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(mattr) = &self.feature {
|
||||||
|
lcc_command.arg(&format!("--mattr={}", mattr));
|
||||||
|
}
|
||||||
|
|
||||||
let lcc_output = lcc_command
|
let lcc_output = lcc_command
|
||||||
.arg(&self.opt_path)
|
.arg(&self.opt_path)
|
||||||
.arg("-o").arg(&self.out_path)
|
.arg("-o").arg(&self.out_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue