Skip to content

Commit

Permalink
[LTO] Fix Veclib flags correctly pass to LTO flags (#78749)
Browse files Browse the repository at this point in the history
Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the `-plugin-opt` flag.
  • Loading branch information
paschalis-mpeis committed Jan 25, 2024
1 parent 12a8bc0 commit 03cf0e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
"-generate-arange-section"));
}

// Pass vector library arguments to LTO.
Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
// Map the vector library names from clang front-end to opt front-end. The
// values are taken from the TargetLibraryInfo class command line options.
std::optional<StringRef> OptVal =
llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
.Case("Accelerate", "Accelerate")
.Case("LIBMVEC", "LIBMVEC-X86")
.Case("MASSV", "MASSV")
.Case("SVML", "SVML")
.Case("SLEEF", "sleefgnuabi")
.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
.Case("ArmPL", "ArmPL")
.Case("none", "none")
.Default(std::nullopt);

if (OptVal)
CmdArgs.push_back(Args.MakeArgString(
Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
}

// Try to pass driver level flags relevant to LTO code generation down to
// the plugin.

Expand Down
18 changes: 18 additions & 0 deletions clang/test/Driver/fveclib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@

// RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target arm64-apple-ios8.0.0 -### 2>&1 | FileCheck --check-prefix=CHECK-LINK-NODEFAULTLIBS %s
// CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"


/* Verify that the correct vector library is passed to LTO flags. */

// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=LIBMVEC -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"

// RUN: %clang -### --target=powerpc64-unknown-linux-gnu -fveclib=MASSV -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-MASSV %s
// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"

// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"

// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-SLEEF %s
// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"

// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-ARMPL %s
// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

0 comments on commit 03cf0e9

Please sign in to comment.