Skip to content

Commit 803c52d

Browse files
committed
Recommit "[Clang,Driver] Add -fveclib=Darwin_libsystem_m support."
Recommit D102489, with the test case requiring the AArch64 backend. This reverts the revert 59b419a.
1 parent d29f7f1 commit 803c52d

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
5555
};
5656

5757
enum VectorLibrary {
58-
NoLibrary, // Don't use any vector library.
59-
Accelerate, // Use the Accelerate framework.
60-
LIBMVEC, // GLIBC vector math library.
61-
MASSV, // IBM MASS vector library.
62-
SVML // Intel short vector math library.
58+
NoLibrary, // Don't use any vector library.
59+
Accelerate, // Use the Accelerate framework.
60+
LIBMVEC, // GLIBC vector math library.
61+
MASSV, // IBM MASS vector library.
62+
SVML, // Intel short vector math library.
63+
Darwin_libsystem_m // Use Darwin's libsytem_m vector functions.
6364
};
6465

6566
enum ObjCDispatchMethodKind {

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,9 +2171,10 @@ def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, Group<f_clang_
21712171
Alias<fno_global_isel>;
21722172
def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>, Flags<[CC1Option]>,
21732173
HelpText<"Use the given vector functions library">,
2174-
Values<"Accelerate,libmvec,MASSV,SVML,none">,
2174+
Values<"Accelerate,libmvec,MASSV,SVML,Darwin_libsystem_m,none">,
21752175
NormalizedValuesScope<"CodeGenOptions">,
2176-
NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "NoLibrary"]>,
2176+
NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML",
2177+
"Darwin_libsystem_m", "NoLibrary"]>,
21772178
MarshallingInfoEnum<CodeGenOpts<"VecLib">, "NoLibrary">;
21782179
def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>,
21792180
Alias<flax_vector_conversions_EQ>, AliasArgs<["none"]>;

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
402402
case CodeGenOptions::SVML:
403403
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
404404
break;
405+
case CodeGenOptions::Darwin_libsystem_m:
406+
TLII->addVectorizableFunctionsFromVecLib(
407+
TargetLibraryInfoImpl::DarwinLibSystemM);
408+
break;
405409
default:
406410
break;
407411
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -fveclib=Darwin_libsystem_m -triple arm64-apple-darwin %s -target-cpu apple-a7 -vectorize-loops -emit-llvm -O3 -o - | FileCheck %s
2+
3+
// REQUIRES: aarch64-registered-target
4+
5+
// Make sure -fveclib=Darwin_libsystem_m gets passed through to LLVM as
6+
// expected: a call to _simd_sin_f4 should be generated.
7+
8+
extern float sinf(float);
9+
10+
// CHECK-LABEL: define{{.*}}@apply_sin
11+
// CHECK: call <4 x float> @_simd_sin_f4(
12+
//
13+
void apply_sin(float *A, float *B, float *C, unsigned N) {
14+
for (unsigned i = 0; i < N; i++)
15+
C[i] = sinf(A[i]) + sinf(B[i]);
16+
}

clang/test/Driver/autocomplete.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
// FLTOALL-NEXT: thin
7777
// RUN: %clang --autocomplete=-fveclib= | FileCheck %s -check-prefix=FVECLIBALL
7878
// FVECLIBALL: Accelerate
79+
// FVECLIBALL-NEXT: Darwin_libsystem_m
7980
// FVECLIBALL-NEXT: libmvec
8081
// FVECLIBALL-NEXT: MASSV
8182
// FVECLIBALL-NEXT: none

clang/test/Driver/fveclib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// RUN: %clang -### -c -fveclib=Accelerate %s 2>&1 | FileCheck -check-prefix CHECK-ACCELERATE %s
33
// RUN: %clang -### -c -fveclib=libmvec %s 2>&1 | FileCheck -check-prefix CHECK-libmvec %s
44
// RUN: %clang -### -c -fveclib=MASSV %s 2>&1 | FileCheck -check-prefix CHECK-MASSV %s
5+
// RUN: %clang -### -c -fveclib=Darwin_libsystem_m %s 2>&1 | FileCheck -check-prefix CHECK-DARWIN_LIBSYSTEM_M %s
56
// RUN: not %clang -c -fveclib=something %s 2>&1 | FileCheck -check-prefix CHECK-INVALID %s
67

78
// CHECK-NOLIB: "-fveclib=none"
89
// CHECK-ACCELERATE: "-fveclib=Accelerate"
910
// CHECK-libmvec: "-fveclib=libmvec"
1011
// CHECK-MASSV: "-fveclib=MASSV"
12+
// CHECK-DARWIN_LIBSYSTEM_M: "-fveclib=Darwin_libsystem_m"
1113

1214
// CHECK-INVALID: error: invalid value 'something' in '-fveclib=something'
1315

0 commit comments

Comments
 (0)