[clang] 187a14e - [Clang, Driver] Add -fveclib=Darwin_libsystem_m support.
Florian Hahn via cfe-commits
cfe-commits at lists.llvm.org
Fri May 14 13:19:02 PDT 2021
Author: Florian Hahn
Date: 2021-05-14T21:00:13+01:00
New Revision: 187a14e1f39942545b905679a8452365dfd87af8
URL: https://github.com/llvm/llvm-project/commit/187a14e1f39942545b905679a8452365dfd87af8
DIFF: https://github.com/llvm/llvm-project/commit/187a14e1f39942545b905679a8452365dfd87af8.diff
LOG: [Clang,Driver] Add -fveclib=Darwin_libsystem_m support.
Support for Darwin's libsystem_m's vector functions has been added to
LLVM in 93a9a8a8d90f.
This patch adds support for -fveclib=Darwin_libsystem_m to Clang.
Reviewed By: arphaman
Differential Revision: https://reviews.llvm.org/D102489
Added:
clang/test/CodeGen/veclib-darwin-libsystem-m.c
Modified:
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/test/Driver/autocomplete.c
clang/test/Driver/fveclib.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 3f06dd3a3f82..65688217878e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -55,11 +55,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
};
enum VectorLibrary {
- NoLibrary, // Don't use any vector library.
- Accelerate, // Use the Accelerate framework.
- LIBMVEC, // GLIBC vector math library.
- MASSV, // IBM MASS vector library.
- SVML // Intel short vector math library.
+ NoLibrary, // Don't use any vector library.
+ Accelerate, // Use the Accelerate framework.
+ LIBMVEC, // GLIBC vector math library.
+ MASSV, // IBM MASS vector library.
+ SVML, // Intel short vector math library.
+ Darwin_libsystem_m // Use Darwin's libsytem_m vector functions.
};
enum ObjCDispatchMethodKind {
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index a7adab50657a..d888467f536a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2171,9 +2171,10 @@ def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, Group<f_clang_
Alias<fno_global_isel>;
def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Use the given vector functions library">,
- Values<"Accelerate,libmvec,MASSV,SVML,none">,
+ Values<"Accelerate,libmvec,MASSV,SVML,Darwin_libsystem_m,none">,
NormalizedValuesScope<"CodeGenOptions">,
- NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "NoLibrary"]>,
+ NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML",
+ "Darwin_libsystem_m", "NoLibrary"]>,
MarshallingInfoEnum<CodeGenOpts<"VecLib">, "NoLibrary">;
def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>,
Alias<flax_vector_conversions_EQ>, AliasArgs<["none"]>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index e2799f6aba4c..fef9d9dcdc90 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -402,6 +402,10 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
case CodeGenOptions::SVML:
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
break;
+ case CodeGenOptions::Darwin_libsystem_m:
+ TLII->addVectorizableFunctionsFromVecLib(
+ TargetLibraryInfoImpl::DarwinLibSystemM);
+ break;
default:
break;
}
diff --git a/clang/test/CodeGen/veclib-darwin-libsystem-m.c b/clang/test/CodeGen/veclib-darwin-libsystem-m.c
new file mode 100644
index 000000000000..cb1f66e22d4a
--- /dev/null
+++ b/clang/test/CodeGen/veclib-darwin-libsystem-m.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fveclib=Darwin_libsystem_m -triple arm64-apple-darwin %s -target-cpu apple-a7 -vectorize-loops -emit-llvm -O3 -o - | FileCheck %s
+
+// Make sure -fveclib=Darwin_libsystem_m gets passed through to LLVM as
+// expected: a call to _simd_sin_f4 should be generated.
+
+extern float sinf(float);
+
+// CHECK-LABEL: define{{.*}}@apply_sin
+// CHECK: call <4 x float> @_simd_sin_f4(
+//
+void apply_sin(float *A, float *B, float *C, unsigned N) {
+ for (unsigned i = 0; i < N; i++)
+ C[i] = sinf(A[i]) + sinf(B[i]);
+}
diff --git a/clang/test/Driver/autocomplete.c b/clang/test/Driver/autocomplete.c
index 85bf6c7912a4..3efe141de6fc 100644
--- a/clang/test/Driver/autocomplete.c
+++ b/clang/test/Driver/autocomplete.c
@@ -76,6 +76,7 @@
// FLTOALL-NEXT: thin
// RUN: %clang --autocomplete=-fveclib= | FileCheck %s -check-prefix=FVECLIBALL
// FVECLIBALL: Accelerate
+// FVECLIBALL-NEXT: Darwin_libsystem_m
// FVECLIBALL-NEXT: libmvec
// FVECLIBALL-NEXT: MASSV
// FVECLIBALL-NEXT: none
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index 5036422f5791..2bf7558a02af 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -2,12 +2,14 @@
// RUN: %clang -### -c -fveclib=Accelerate %s 2>&1 | FileCheck -check-prefix CHECK-ACCELERATE %s
// RUN: %clang -### -c -fveclib=libmvec %s 2>&1 | FileCheck -check-prefix CHECK-libmvec %s
// RUN: %clang -### -c -fveclib=MASSV %s 2>&1 | FileCheck -check-prefix CHECK-MASSV %s
+// RUN: %clang -### -c -fveclib=Darwin_libsystem_m %s 2>&1 | FileCheck -check-prefix CHECK-DARWIN_LIBSYSTEM_M %s
// RUN: not %clang -c -fveclib=something %s 2>&1 | FileCheck -check-prefix CHECK-INVALID %s
// CHECK-NOLIB: "-fveclib=none"
// CHECK-ACCELERATE: "-fveclib=Accelerate"
// CHECK-libmvec: "-fveclib=libmvec"
// CHECK-MASSV: "-fveclib=MASSV"
+// CHECK-DARWIN_LIBSYSTEM_M: "-fveclib=Darwin_libsystem_m"
// CHECK-INVALID: error: invalid value 'something' in '-fveclib=something'
More information about the cfe-commits
mailing list