Skip to content

Commit e1f9741

Browse files
[LTO] Fix Veclib flags correctly pass to LTO flags
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 9774746 commit e1f9741

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
783783
"-generate-arange-section"));
784784
}
785785

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

clang/test/Driver/fveclib.c

+28
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,31 @@
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+
39+
// RUN: %clang -### -fveclib=none -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-NOLIB %s
40+
// CHECK-LTO-NOLIB: "-plugin-opt=-vector-library=none"
41+
42+
// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-ACCELERATE %s
43+
// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
44+
45+
// RUN: %clang -### -fveclib=LIBMVEC -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
46+
// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
47+
48+
// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-MASSV %s
49+
// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
50+
51+
// RUN: not %clang -### -fveclib=SVML -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
52+
// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
53+
54+
// RUN: %clang -### -fveclib=SLEEF -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-SLEEF %s
55+
// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
56+
57+
// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-DARWIN %s
58+
// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
59+
60+
// RUN: %clang -### -fveclib=ArmPL -flto %s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-ARMPL %s
61+
// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

0 commit comments

Comments
 (0)