Skip to content

Commit caed089

Browse files
authored
TargetLibraryInfo: Split off VectorLibrary enum and flag (#166980)
Move this to a new shared header to facilitate the eventual merger of RuntimeLibcallsInfo and TargetLibraryInfo. Ideally this would be replaced with a module flag. For now put it into a common header both can use.
1 parent 7fe60a7 commit caed089

File tree

6 files changed

+94
-59
lines changed

6 files changed

+94
-59
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace llvm {
2424

2525
template <typename T> class ArrayRef;
26+
enum class VectorLibrary;
2627

2728
/// Provides info so a possible vectorization of a function can be
2829
/// computed. Function 'VectorFnName' is equivalent to 'ScalarFnName'
@@ -117,25 +118,6 @@ class TargetLibraryInfoImpl {
117118
const Module &M) const;
118119

119120
public:
120-
/// List of known vector-functions libraries.
121-
///
122-
/// The vector-functions library defines, which functions are vectorizable
123-
/// and with which factor. The library can be specified by either frontend,
124-
/// or a commandline option, and then used by
125-
/// addVectorizableFunctionsFromVecLib for filling up the tables of
126-
/// vectorizable functions.
127-
enum VectorLibrary {
128-
NoLibrary, // Don't use any vector library.
129-
Accelerate, // Use Accelerate framework.
130-
DarwinLibSystemM, // Use Darwin's libsystem_m.
131-
LIBMVEC, // GLIBC Vector Math library.
132-
MASSV, // IBM MASS vector library.
133-
SVML, // Intel short vector math library.
134-
SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.
135-
ArmPL, // Arm Performance Libraries.
136-
AMDLIBM // AMD Math Vector library.
137-
};
138-
139121
TargetLibraryInfoImpl() = delete;
140122
LLVM_ABI explicit TargetLibraryInfoImpl(const Triple &T);
141123

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===------------------------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_IR_SYSTEMLIBRARIES_H
10+
#define LLVM_IR_SYSTEMLIBRARIES_H
11+
12+
namespace llvm {
13+
/// List of known vector-functions libraries.
14+
///
15+
/// The vector-functions library defines, which functions are vectorizable
16+
/// and with which factor. The library can be specified by either frontend,
17+
/// or a commandline option, and then used by
18+
/// addVectorizableFunctionsFromVecLib for filling up the tables of
19+
/// vectorizable functions.
20+
enum class VectorLibrary {
21+
NoLibrary, // Don't use any vector library.
22+
Accelerate, // Use Accelerate framework.
23+
DarwinLibSystemM, // Use Darwin's libsystem_m.
24+
LIBMVEC, // GLIBC Vector Math library.
25+
MASSV, // IBM MASS vector library.
26+
SVML, // Intel short vector math library.
27+
SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.
28+
ArmPL, // Arm Performance Libraries.
29+
AMDLIBM // AMD Math Vector library.
30+
};
31+
32+
/// Command line flag value for the vector math library to use
33+
///
34+
/// FIXME: This should come from a module flag, and not be mutually exclusive
35+
extern VectorLibrary ClVectorLibrary;
36+
37+
} // namespace llvm
38+
39+
#endif // LLVM_IR_SYSTEMLIBRARIES_H

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,11 @@
1515
#include "llvm/ADT/SmallString.h"
1616
#include "llvm/IR/Constants.h"
1717
#include "llvm/IR/Module.h"
18+
#include "llvm/IR/SystemLibraries.h"
1819
#include "llvm/InitializePasses.h"
19-
#include "llvm/Support/CommandLine.h"
2020
#include "llvm/TargetParser/Triple.h"
2121
using namespace llvm;
2222

23-
static cl::opt<TargetLibraryInfoImpl::VectorLibrary> ClVectorLibrary(
24-
"vector-library", cl::Hidden, cl::desc("Vector functions library"),
25-
cl::init(TargetLibraryInfoImpl::NoLibrary),
26-
cl::values(clEnumValN(TargetLibraryInfoImpl::NoLibrary, "none",
27-
"No vector functions library"),
28-
clEnumValN(TargetLibraryInfoImpl::Accelerate, "Accelerate",
29-
"Accelerate framework"),
30-
clEnumValN(TargetLibraryInfoImpl::DarwinLibSystemM,
31-
"Darwin_libsystem_m", "Darwin libsystem_m"),
32-
clEnumValN(TargetLibraryInfoImpl::LIBMVEC, "LIBMVEC",
33-
"GLIBC Vector Math library"),
34-
clEnumValN(TargetLibraryInfoImpl::MASSV, "MASSV",
35-
"IBM MASS vector library"),
36-
clEnumValN(TargetLibraryInfoImpl::SVML, "SVML",
37-
"Intel SVML library"),
38-
clEnumValN(TargetLibraryInfoImpl::SLEEFGNUABI, "sleefgnuabi",
39-
"SIMD Library for Evaluating Elementary Functions"),
40-
clEnumValN(TargetLibraryInfoImpl::ArmPL, "ArmPL",
41-
"Arm Performance Libraries"),
42-
clEnumValN(TargetLibraryInfoImpl::AMDLIBM, "AMDLIBM",
43-
"AMD vector math library")));
44-
4523
StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
4624
{
4725
#define TLI_DEFINE_STRING
@@ -1392,15 +1370,15 @@ const VecDesc VecFuncs_AMDLIBM[] = {
13921370
void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
13931371
enum VectorLibrary VecLib, const llvm::Triple &TargetTriple) {
13941372
switch (VecLib) {
1395-
case Accelerate: {
1373+
case VectorLibrary::Accelerate: {
13961374
addVectorizableFunctions(VecFuncs_Accelerate);
13971375
break;
13981376
}
1399-
case DarwinLibSystemM: {
1377+
case VectorLibrary::DarwinLibSystemM: {
14001378
addVectorizableFunctions(VecFuncs_DarwinLibSystemM);
14011379
break;
14021380
}
1403-
case LIBMVEC: {
1381+
case VectorLibrary::LIBMVEC: {
14041382
switch (TargetTriple.getArch()) {
14051383
default:
14061384
break;
@@ -1415,15 +1393,15 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
14151393
}
14161394
break;
14171395
}
1418-
case MASSV: {
1396+
case VectorLibrary::MASSV: {
14191397
addVectorizableFunctions(VecFuncs_MASSV);
14201398
break;
14211399
}
1422-
case SVML: {
1400+
case VectorLibrary::SVML: {
14231401
addVectorizableFunctions(VecFuncs_SVML);
14241402
break;
14251403
}
1426-
case SLEEFGNUABI: {
1404+
case VectorLibrary::SLEEFGNUABI: {
14271405
switch (TargetTriple.getArch()) {
14281406
default:
14291407
break;
@@ -1439,7 +1417,7 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
14391417
}
14401418
break;
14411419
}
1442-
case ArmPL: {
1420+
case VectorLibrary::ArmPL: {
14431421
switch (TargetTriple.getArch()) {
14441422
default:
14451423
break;
@@ -1450,11 +1428,11 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
14501428
}
14511429
break;
14521430
}
1453-
case AMDLIBM: {
1431+
case VectorLibrary::AMDLIBM: {
14541432
addVectorizableFunctions(VecFuncs_AMDLIBM);
14551433
break;
14561434
}
1457-
case NoLibrary:
1435+
case VectorLibrary::NoLibrary:
14581436
break;
14591437
}
14601438
}

llvm/lib/Frontend/Driver/CodeGenOptions.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llvm/Frontend/Driver/CodeGenOptions.h"
1010
#include "llvm/Analysis/TargetLibraryInfo.h"
11+
#include "llvm/IR/SystemLibraries.h"
1112
#include "llvm/ProfileData/InstrProfCorrelator.h"
1213
#include "llvm/TargetParser/Triple.h"
1314

@@ -25,35 +26,35 @@ TargetLibraryInfoImpl *createTLII(const llvm::Triple &TargetTriple,
2526
using VectorLibrary = llvm::driver::VectorLibrary;
2627
switch (Veclib) {
2728
case VectorLibrary::Accelerate:
28-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate,
29+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::Accelerate,
2930
TargetTriple);
3031
break;
3132
case VectorLibrary::LIBMVEC:
32-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::LIBMVEC,
33+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::LIBMVEC,
3334
TargetTriple);
3435
break;
3536
case VectorLibrary::MASSV:
36-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::MASSV,
37+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::MASSV,
3738
TargetTriple);
3839
break;
3940
case VectorLibrary::SVML:
40-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML,
41+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::SVML,
4142
TargetTriple);
4243
break;
4344
case VectorLibrary::SLEEF:
44-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SLEEFGNUABI,
45+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::SLEEFGNUABI,
4546
TargetTriple);
4647
break;
4748
case VectorLibrary::Darwin_libsystem_m:
4849
TLII->addVectorizableFunctionsFromVecLib(
49-
TargetLibraryInfoImpl::DarwinLibSystemM, TargetTriple);
50+
llvm::VectorLibrary::DarwinLibSystemM, TargetTriple);
5051
break;
5152
case VectorLibrary::ArmPL:
52-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::ArmPL,
53+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::ArmPL,
5354
TargetTriple);
5455
break;
5556
case VectorLibrary::AMDLIBM:
56-
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::AMDLIBM,
57+
TLII->addVectorizableFunctionsFromVecLib(llvm::VectorLibrary::AMDLIBM,
5758
TargetTriple);
5859
break;
5960
default:

llvm/lib/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ add_llvm_component_library(LLVMCore
6767
ReplaceConstant.cpp
6868
Statepoint.cpp
6969
StructuralHash.cpp
70+
SystemLibraries.cpp
7071
Type.cpp
7172
TypedPointerType.cpp
7273
TypeFinder.cpp

llvm/lib/IR/SystemLibraries.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-----------------------------------------------------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/IR/SystemLibraries.h"
10+
#include "llvm/Support/CommandLine.h"
11+
12+
using namespace llvm;
13+
14+
VectorLibrary llvm::ClVectorLibrary;
15+
16+
static cl::opt<VectorLibrary, true> ClVectorLibraryOpt(
17+
"vector-library", cl::Hidden, cl::desc("Vector functions library"),
18+
cl::location(llvm::ClVectorLibrary), cl::init(VectorLibrary::NoLibrary),
19+
cl::values(
20+
clEnumValN(VectorLibrary::NoLibrary, "none",
21+
"No vector functions library"),
22+
clEnumValN(VectorLibrary::Accelerate, "Accelerate",
23+
"Accelerate framework"),
24+
clEnumValN(VectorLibrary::DarwinLibSystemM, "Darwin_libsystem_m",
25+
"Darwin libsystem_m"),
26+
clEnumValN(VectorLibrary::LIBMVEC, "LIBMVEC",
27+
"GLIBC Vector Math library"),
28+
clEnumValN(VectorLibrary::MASSV, "MASSV", "IBM MASS vector library"),
29+
clEnumValN(VectorLibrary::SVML, "SVML", "Intel SVML library"),
30+
clEnumValN(VectorLibrary::SLEEFGNUABI, "sleefgnuabi",
31+
"SIMD Library for Evaluating Elementary Functions"),
32+
clEnumValN(VectorLibrary::ArmPL, "ArmPL", "Arm Performance Libraries"),
33+
clEnumValN(VectorLibrary::AMDLIBM, "AMDLIBM",
34+
"AMD vector math library")));

0 commit comments

Comments
 (0)