Skip to content

Commit 03cf0e9

Browse files
[LTO] Fix Veclib flags correctly pass to LTO flags (#78749)
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.
1 parent 12a8bc0 commit 03cf0e9

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
781781
"-generate-arange-section"));
782782
}
783783

784+
// Pass vector library arguments to LTO.
785+
Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
786+
if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
787+
// Map the vector library names from clang front-end to opt front-end. The
788+
// values are taken from the TargetLibraryInfo class command line options.
789+
std::optional<StringRef> OptVal =
790+
llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
791+
.Case("Accelerate", "Accelerate")
792+
.Case("LIBMVEC", "LIBMVEC-X86")
793+
.Case("MASSV", "MASSV")
794+
.Case("SVML", "SVML")
795+
.Case("SLEEF", "sleefgnuabi")
796+
.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
797+
.Case("ArmPL", "ArmPL")
798+
.Case("none", "none")
799+
.Default(std::nullopt);
800+
801+
if (OptVal)
802+
CmdArgs.push_back(Args.MakeArgString(
803+
Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
804+
}
805+
784806
// Try to pass driver level flags relevant to LTO code generation down to
785807
// the plugin.
786808

clang/test/Driver/fveclib.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,21 @@
3131

3232
// RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target arm64-apple-ios8.0.0 -### 2>&1 | FileCheck --check-prefix=CHECK-LINK-NODEFAULTLIBS %s
3333
// CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
34+
35+
36+
/* Verify that the correct vector library is passed to LTO flags. */
37+
38+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=LIBMVEC -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
39+
// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
40+
41+
// RUN: %clang -### --target=powerpc64-unknown-linux-gnu -fveclib=MASSV -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-MASSV %s
42+
// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
43+
44+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
45+
// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
46+
47+
// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-SLEEF %s
48+
// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
49+
50+
// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s 2>&1 | FileCheck -check-prefix CHECK-LTO-ARMPL %s
51+
// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

0 commit comments

Comments
 (0)