Skip to content

Commit 13f287a

Browse files
paschalis-mpeiststellar
authored andcommitted
[LTO] Fix Veclib flags correctly pass to LTO flags (llvm#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. (cherry picked from commit 03cf0e9)
1 parent 40b33b3 commit 13f287a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
810810
"-generate-arange-section"));
811811
}
812812

813+
// Pass vector library arguments to LTO.
814+
Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
815+
if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
816+
// Map the vector library names from clang front-end to opt front-end. The
817+
// values are taken from the TargetLibraryInfo class command line options.
818+
std::optional<StringRef> OptVal =
819+
llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
820+
.Case("Accelerate", "Accelerate")
821+
.Case("LIBMVEC", "LIBMVEC-X86")
822+
.Case("MASSV", "MASSV")
823+
.Case("SVML", "SVML")
824+
.Case("SLEEF", "sleefgnuabi")
825+
.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
826+
.Case("ArmPL", "ArmPL")
827+
.Case("none", "none")
828+
.Default(std::nullopt);
829+
830+
if (OptVal)
831+
CmdArgs.push_back(Args.MakeArgString(
832+
Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
833+
}
834+
813835
// Try to pass driver level flags relevant to LTO code generation down to
814836
// the plugin.
815837

clang/test/Driver/fveclib.c

+18
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)