Skip to content

Commit b7d3c9c

Browse files
committed
Changed struct VecDesc into a class VecDesc and adjusted
the functionality.
1 parent 38db22f commit b7d3c9c

File tree

5 files changed

+65
-35
lines changed

5 files changed

+65
-35
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,27 @@ class Triple;
4040
/// <vparams> = "v", as many as are the numArgs.
4141
/// <scalarname> = the name of the scalar function.
4242
/// <vectorname> = the name of the vector function.
43-
struct VecDesc {
43+
class VecDesc {
44+
private:
4445
StringRef ScalarFnName;
4546
StringRef VectorFnName;
4647
ElementCount VectorizationFactor;
4748
bool Masked;
4849
StringRef MangledName;
50+
51+
public:
52+
VecDesc() = delete;
53+
VecDesc(StringRef ScalarFnName, StringRef VectorFnName,
54+
ElementCount VectorizationFactor, bool Masked, StringRef MangledName)
55+
: ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
56+
VectorizationFactor(VectorizationFactor), Masked(Masked),
57+
MangledName(MangledName) {}
58+
59+
StringRef getScalarFnName() const { return ScalarFnName; }
60+
StringRef getVectorFnName() const { return VectorFnName; }
61+
ElementCount getVectorizationFactor() const { return VectorizationFactor; }
62+
bool getMasked() const { return Masked; }
63+
StringRef getMangledName() const { return MangledName; }
4964
};
5065

5166
enum LibFunc : unsigned {
@@ -177,18 +192,24 @@ class TargetLibraryInfoImpl {
177192
/// Return true if the function F has a vector equivalent with vectorization
178193
/// factor VF.
179194
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const {
180-
return !(getVectorizedFunction(F, VF, false).first.empty() &&
181-
getVectorizedFunction(F, VF, true).first.empty());
195+
return !(getVectorizedFunction(F, VF, false).empty() &&
196+
getVectorizedFunction(F, VF, true).empty());
182197
}
183198

184199
/// Return true if the function F has a vector equivalent with any
185200
/// vectorization factor.
186201
bool isFunctionVectorizable(StringRef F) const;
187202

188-
/// Return the name of the equivalent of F, vectorized with factor VF and it's
189-
/// mangled name. If no such mapping exists, return empty strings.
190-
std::pair<StringRef, StringRef>
191-
getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked) const;
203+
/// Return the name of the equivalent of F, vectorized with factor VF.
204+
/// If no such mapping exists, return empty strings.
205+
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF,
206+
bool Masked) const;
207+
208+
/// Return a pointer to a VecDesc object holding all info for scalar to vector
209+
/// mappings in TLI for the equivalent of F, vectorized with factor VF.
210+
/// If no such mapping exists, return nullpointer.
211+
const VecDesc *getMangledTLIVectorName(StringRef F, const ElementCount &VF,
212+
bool Masked) const;
192213

193214
/// Set to true iff i32 parameters to library functions should have signext
194215
/// or zeroext attributes if they correspond to C-level int or unsigned int,
@@ -364,11 +385,14 @@ class TargetLibraryInfo {
364385
bool isFunctionVectorizable(StringRef F) const {
365386
return Impl->isFunctionVectorizable(F);
366387
}
367-
std::pair<StringRef, StringRef>
368-
getVectorizedFunction(StringRef F, const ElementCount &VF,
369-
bool Masked = false) const {
388+
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF,
389+
bool Masked = false) const {
370390
return Impl->getVectorizedFunction(F, VF, Masked);
371391
}
392+
const VecDesc *getMangledTLIVectorName(StringRef F, const ElementCount &VF,
393+
bool Masked) const {
394+
return Impl->getMangledTLIVectorName(F, VF, Masked);
395+
}
372396

373397
/// Tests if the function is both available and a candidate for optimized code
374398
/// generation.

llvm/include/llvm/Analysis/VecFuncs.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ TLI_DEFINE_VECFUNC("cbrt", "__cbrtd2", FIXED(2), "_ZGV_LLVM_N2v_cbrt(__cbrtd2)")
209209
TLI_DEFINE_VECFUNC("cbrtf", "__cbrtf4", FIXED(4), "_ZGV_LLVM_N4v_cbrtf(__cbrtf4)")
210210
TLI_DEFINE_VECFUNC("pow", "__powd2", FIXED(2), "_ZGV_LLVM_N2vv_pow(__powd2)")
211211
TLI_DEFINE_VECFUNC("llvm.pow.f64", "__powd2", FIXED(2), "_ZGV_LLVM_N2vv_llvm.pow.f64(__powd2)")
212-
TLI_DEFINE_VECFUNC("powf", "__powf4", FIXED(4), "_ZGV_LLVM_N4vv_powf")
212+
TLI_DEFINE_VECFUNC("powf", "__powf4", FIXED(4), "_ZGV_LLVM_N4vv_powf(__powf4)")
213213
TLI_DEFINE_VECFUNC("llvm.pow.f32", "__powf4", FIXED(4), "_ZGV_LLVM_N4vv_llvm.pow.f32(__powf4)")
214214

215215
// Exponential and Logarithmic Functions

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,15 +1138,15 @@ void TargetLibraryInfoImpl::disableAllFunctions() {
11381138
}
11391139

11401140
static bool compareByScalarFnName(const VecDesc &LHS, const VecDesc &RHS) {
1141-
return LHS.ScalarFnName < RHS.ScalarFnName;
1141+
return LHS.getScalarFnName() < RHS.getScalarFnName();
11421142
}
11431143

11441144
static bool compareByVectorFnName(const VecDesc &LHS, const VecDesc &RHS) {
1145-
return LHS.VectorFnName < RHS.VectorFnName;
1145+
return LHS.getVectorFnName() < RHS.getVectorFnName();
11461146
}
11471147

11481148
static bool compareWithScalarFnName(const VecDesc &LHS, StringRef S) {
1149-
return LHS.ScalarFnName < S;
1149+
return LHS.getScalarFnName() < S;
11501150
}
11511151

11521152
void TargetLibraryInfoImpl::addVectorizableFunctions(ArrayRef<VecDesc> Fns) {
@@ -1262,22 +1262,31 @@ bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
12621262

12631263
std::vector<VecDesc>::const_iterator I =
12641264
llvm::lower_bound(VectorDescs, funcName, compareWithScalarFnName);
1265-
return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
1265+
return I != VectorDescs.end() && StringRef(I->getScalarFnName()) == funcName;
12661266
}
12671267

1268-
std::pair<StringRef, StringRef> TargetLibraryInfoImpl::getVectorizedFunction(
1268+
StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
1269+
const ElementCount &VF,
1270+
bool Masked) const {
1271+
const VecDesc *VD = getMangledTLIVectorName(F, VF, Masked);
1272+
if (VD)
1273+
return VD->getVectorFnName();
1274+
return StringRef();
1275+
}
1276+
1277+
const VecDesc *TargetLibraryInfoImpl::getMangledTLIVectorName(
12691278
StringRef F, const ElementCount &VF, bool Masked) const {
12701279
F = sanitizeFunctionName(F);
12711280
if (F.empty())
1272-
return std::make_pair(F, StringRef());
1281+
return nullptr;
12731282
std::vector<VecDesc>::const_iterator I =
12741283
llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
1275-
while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
1276-
if ((I->VectorizationFactor == VF) && (I->Masked == Masked))
1277-
return std::make_pair(I->VectorFnName, I->MangledName);
1284+
while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == F) {
1285+
if ((I->getVectorizationFactor() == VF) && (I->getMasked() == Masked))
1286+
return &(*I);
12781287
++I;
12791288
}
1280-
return std::make_pair(StringRef(), StringRef());
1289+
return nullptr;
12811290
}
12821291

12831292
TargetLibraryInfo TargetLibraryAnalysis::run(const Function &F,
@@ -1349,11 +1358,11 @@ void TargetLibraryInfoImpl::getWidestVF(StringRef ScalarF,
13491358

13501359
std::vector<VecDesc>::const_iterator I =
13511360
llvm::lower_bound(VectorDescs, ScalarF, compareWithScalarFnName);
1352-
while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == ScalarF) {
1361+
while (I != VectorDescs.end() && StringRef(I->getScalarFnName()) == ScalarF) {
13531362
ElementCount *VF =
1354-
I->VectorizationFactor.isScalable() ? &ScalableVF : &FixedVF;
1355-
if (ElementCount::isKnownGT(I->VectorizationFactor, *VF))
1356-
*VF = I->VectorizationFactor;
1363+
I->getVectorizationFactor().isScalable() ? &ScalableVF : &FixedVF;
1364+
if (ElementCount::isKnownGT(I->getVectorizationFactor(), *VF))
1365+
*VF = I->getVectorizationFactor();
13571366
++I;
13581367
}
13591368
}

llvm/lib/CodeGen/ReplaceWithVeclib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI,
155155
// Try to find the mapping for the scalar version of this intrinsic
156156
// and the exact vector width of the call operands in the
157157
// TargetLibraryInfo.
158-
StringRef TLIName = TLI.getVectorizedFunction(ScalarName, VF).first;
158+
StringRef TLIName = TLI.getVectorizedFunction(ScalarName, VF);
159159

160160
LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": Looking up TLI mapping for `"
161161
<< ScalarName << "` and vector width " << VF << ".\n");

llvm/lib/Transforms/Utils/InjectTLIMappings.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,15 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {
9191
Mappings.end());
9292

9393
auto AddVariantDecl = [&](const ElementCount &VF, bool Predicate) {
94-
StringRef TLIName;
95-
StringRef MangledName;
96-
std::tie(TLIName, MangledName) =
97-
TLI.getVectorizedFunction(ScalarName, VF, Predicate);
98-
if (!TLIName.empty() && !MangledName.empty()) {
99-
if (!OriginalSetOfMappings.count(std::string(MangledName))) {
100-
Mappings.push_back(std::string(MangledName));
94+
const VecDesc *VD = TLI.getMangledTLIVectorName(ScalarName, VF, Predicate);
95+
if (VD) {
96+
if (!OriginalSetOfMappings.count(std::string(VD->getMangledName()))) {
97+
Mappings.push_back(std::string(VD->getMangledName()));
10198
++NumCallInjected;
10299
}
103-
Function *VariantF = M->getFunction(TLIName);
100+
Function *VariantF = M->getFunction(VD->getVectorFnName());
104101
if (!VariantF)
105-
addVariantDeclaration(CI, VF, Predicate, TLIName);
102+
addVariantDeclaration(CI, VF, Predicate, VD->getVectorFnName());
106103
}
107104
};
108105

0 commit comments

Comments
 (0)