Linking arguments for LLVM passes (#1273)

This commit is contained in:
Dongjia "toka" Zhang 2023-05-17 13:53:02 +02:00 committed by GitHub
parent 20f8cb10eb
commit b7c1591b00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,6 +89,7 @@ pub struct ClangWrapper {
link_args: Vec<String>, link_args: Vec<String>,
passes: Vec<LLVMPasses>, passes: Vec<LLVMPasses>,
passes_args: Vec<String>, passes_args: Vec<String>,
passes_linking_args: Vec<String>,
} }
#[allow(clippy::match_same_arms)] // for the linking = false wip for "shared" #[allow(clippy::match_same_arms)] // for the linking = false wip for "shared"
@ -302,6 +303,8 @@ impl CompilerWrapper for ClangWrapper {
fn command(&mut self) -> Result<Vec<String>, Error> { fn command(&mut self) -> Result<Vec<String>, Error> {
let mut args = vec![]; let mut args = vec![];
let mut use_pass = false;
if self.is_cpp { if self.is_cpp {
args.push(self.wrapped_cxx.clone()); args.push(self.wrapped_cxx.clone());
} else { } else {
@ -324,6 +327,7 @@ impl CompilerWrapper for ClangWrapper {
} }
} }
for pass in &self.passes { for pass in &self.passes {
use_pass = true;
if self.use_new_pm { if self.use_new_pm {
// https://github.com/llvm/llvm-project/issues/56137 // https://github.com/llvm/llvm-project/issues/56137
// Need this -Xclang -load -Xclang -<pass>.so thing even with the new PM // Need this -Xclang -load -Xclang -<pass>.so thing even with the new PM
@ -358,6 +362,10 @@ impl CompilerWrapper for ClangWrapper {
args.extend_from_slice(self.link_args.as_slice()); args.extend_from_slice(self.link_args.as_slice());
if use_pass {
args.extend_from_slice(self.passes_linking_args.as_slice());
}
if cfg!(unix) { if cfg!(unix) {
args.push("-pthread".into()); args.push("-pthread".into());
args.push("-ldl".into()); args.push("-ldl".into());
@ -423,6 +431,7 @@ impl ClangWrapper {
link_args: vec![], link_args: vec![],
passes: vec![], passes: vec![],
passes_args: vec![], passes_args: vec![],
passes_linking_args: vec![],
is_silent: false, is_silent: false,
} }
} }
@ -466,6 +475,15 @@ impl ClangWrapper {
self self
} }
/// Add arguments for LLVM passes during linking. For example, ngram needs -lm
pub fn add_passes_linking_arg<S>(&mut self, arg: S) -> &'_ mut Self
where
S: AsRef<str>,
{
self.passes_linking_args.push(arg.as_ref().to_string());
self
}
/// Set if linking /// Set if linking
pub fn linking(&mut self, value: bool) -> &'_ mut Self { pub fn linking(&mut self, value: bool) -> &'_ mut Self {
self.linking = value; self.linking = value;