12
12
13
13
#include " llvm/Analysis/TargetLibraryInfo.h"
14
14
#include " llvm/ADT/DenseMap.h"
15
+ #include " llvm/ADT/SmallString.h"
15
16
#include " llvm/IR/Constants.h"
16
17
#include " llvm/InitializePasses.h"
17
18
#include " llvm/Support/CommandLine.h"
@@ -44,6 +45,13 @@ StringLiteral const TargetLibraryInfoImpl::StandardNames[LibFunc::NumLibFuncs] =
44
45
#include " llvm/Analysis/TargetLibraryInfo.def"
45
46
};
46
47
48
+ std::string VecDesc::getVectorFunctionABIVariantString () const {
49
+ SmallString<256 > Buffer;
50
+ llvm::raw_svector_ostream Out (Buffer);
51
+ Out << VABIPrefix << " _" << ScalarFnName << " (" << VectorFnName << " )" ;
52
+ return std::string (Out.str ());
53
+ }
54
+
47
55
// Recognized types of library function arguments and return types.
48
56
enum FuncArgTypeID : char {
49
57
Void = 0 , // Must be zero.
@@ -1138,15 +1146,15 @@ void TargetLibraryInfoImpl::disableAllFunctions() {
1138
1146
}
1139
1147
1140
1148
static bool compareByScalarFnName (const VecDesc &LHS, const VecDesc &RHS) {
1141
- return LHS.ScalarFnName < RHS.ScalarFnName ;
1149
+ return LHS.getScalarFnName () < RHS.getScalarFnName () ;
1142
1150
}
1143
1151
1144
1152
static bool compareByVectorFnName (const VecDesc &LHS, const VecDesc &RHS) {
1145
- return LHS.VectorFnName < RHS.VectorFnName ;
1153
+ return LHS.getVectorFnName () < RHS.getVectorFnName () ;
1146
1154
}
1147
1155
1148
1156
static bool compareWithScalarFnName (const VecDesc &LHS, StringRef S) {
1149
- return LHS.ScalarFnName < S;
1157
+ return LHS.getScalarFnName () < S;
1150
1158
}
1151
1159
1152
1160
void TargetLibraryInfoImpl::addVectorizableFunctions (ArrayRef<VecDesc> Fns) {
@@ -1203,17 +1211,20 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1203
1211
case SLEEFGNUABI: {
1204
1212
const VecDesc VecFuncs_VF2[] = {
1205
1213
#define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
1206
- #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF ) {SCAL, VEC, VF, /* MASK = */ false },
1214
+ #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF, VABI_PREFIX ) \
1215
+ {SCAL, VEC, VF, /* MASK = */ false , VABI_PREFIX},
1207
1216
#include " llvm/Analysis/VecFuncs.def"
1208
1217
};
1209
1218
const VecDesc VecFuncs_VF4[] = {
1210
1219
#define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
1211
- #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF ) {SCAL, VEC, VF, /* MASK = */ false },
1220
+ #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF, VABI_PREFIX ) \
1221
+ {SCAL, VEC, VF, /* MASK = */ false , VABI_PREFIX},
1212
1222
#include " llvm/Analysis/VecFuncs.def"
1213
1223
};
1214
1224
const VecDesc VecFuncs_VFScalable[] = {
1215
1225
#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
1216
- #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF, MASK ) {SCAL, VEC, VF, MASK},
1226
+ #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF, MASK, VABI_PREFIX ) \
1227
+ {SCAL, VEC, VF, MASK, VABI_PREFIX},
1217
1228
#include " llvm/Analysis/VecFuncs.def"
1218
1229
};
1219
1230
@@ -1232,7 +1243,8 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
1232
1243
case ArmPL: {
1233
1244
const VecDesc VecFuncs[] = {
1234
1245
#define TLI_DEFINE_ARMPL_VECFUNCS
1235
- #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF, MASK ) {SCAL, VEC, VF, MASK},
1246
+ #define TLI_DEFINE_VECFUNC (SCAL, VEC, VF, MASK, VABI_PREFIX ) \
1247
+ {SCAL, VEC, VF, MASK, VABI_PREFIX},
1236
1248
#include " llvm/Analysis/VecFuncs.def"
1237
1249
};
1238
1250
@@ -1258,23 +1270,32 @@ bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
1258
1270
1259
1271
std::vector<VecDesc>::const_iterator I =
1260
1272
llvm::lower_bound (VectorDescs, funcName, compareWithScalarFnName);
1261
- return I != VectorDescs.end () && StringRef (I->ScalarFnName ) == funcName;
1273
+ return I != VectorDescs.end () && StringRef (I->getScalarFnName () ) == funcName;
1262
1274
}
1263
1275
1264
1276
StringRef TargetLibraryInfoImpl::getVectorizedFunction (StringRef F,
1265
1277
const ElementCount &VF,
1266
1278
bool Masked) const {
1279
+ const VecDesc *VD = getVectorMappingInfo (F, VF, Masked);
1280
+ if (VD)
1281
+ return VD->getVectorFnName ();
1282
+ return StringRef ();
1283
+ }
1284
+
1285
+ const VecDesc *
1286
+ TargetLibraryInfoImpl::getVectorMappingInfo (StringRef F, const ElementCount &VF,
1287
+ bool Masked) const {
1267
1288
F = sanitizeFunctionName (F);
1268
1289
if (F.empty ())
1269
- return F ;
1290
+ return nullptr ;
1270
1291
std::vector<VecDesc>::const_iterator I =
1271
1292
llvm::lower_bound (VectorDescs, F, compareWithScalarFnName);
1272
- while (I != VectorDescs.end () && StringRef (I->ScalarFnName ) == F) {
1273
- if ((I->VectorizationFactor == VF) && (I->Masked == Masked))
1274
- return I-> VectorFnName ;
1293
+ while (I != VectorDescs.end () && StringRef (I->getScalarFnName () ) == F) {
1294
+ if ((I->getVectorizationFactor () == VF) && (I->isMasked () == Masked))
1295
+ return &(*I) ;
1275
1296
++I;
1276
1297
}
1277
- return StringRef () ;
1298
+ return nullptr ;
1278
1299
}
1279
1300
1280
1301
TargetLibraryInfo TargetLibraryAnalysis::run (const Function &F,
@@ -1346,11 +1367,11 @@ void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF,
1346
1367
1347
1368
std::vector<VecDesc>::const_iterator I =
1348
1369
llvm::lower_bound (VectorDescs, ScalarF, compareWithScalarFnName);
1349
- while (I != VectorDescs.end () && StringRef (I->ScalarFnName ) == ScalarF) {
1370
+ while (I != VectorDescs.end () && StringRef (I->getScalarFnName () ) == ScalarF) {
1350
1371
ElementCount *VF =
1351
- I->VectorizationFactor .isScalable () ? &ScalableVF : &FixedVF;
1352
- if (ElementCount::isKnownGT (I->VectorizationFactor , *VF))
1353
- *VF = I->VectorizationFactor ;
1372
+ I->getVectorizationFactor () .isScalable () ? &ScalableVF : &FixedVF;
1373
+ if (ElementCount::isKnownGT (I->getVectorizationFactor () , *VF))
1374
+ *VF = I->getVectorizationFactor () ;
1354
1375
++I;
1355
1376
}
1356
1377
}
0 commit comments