Skip to content

Commit

Permalink
Revert "[TLI][AArch64] Extend SLEEF vectorized functions mapping with…
Browse files Browse the repository at this point in the history
… VLA functions"

Reverting it so I could land it with Arcanist.

This reverts commit 59dcf92.
  • Loading branch information
pawosm-arm committed Mar 29, 2023
1 parent 06f28f2 commit f8f1909
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 212 deletions.
12 changes: 4 additions & 8 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct VecDesc {
StringRef ScalarFnName;
StringRef VectorFnName;
ElementCount VectorizationFactor;
bool Masked;
};

enum LibFunc : unsigned {
Expand Down Expand Up @@ -162,8 +161,7 @@ class TargetLibraryInfoImpl {
/// Return true if the function F has a vector equivalent with vectorization
/// factor VF.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const {
return !(getVectorizedFunction(F, VF, false).empty() &&
getVectorizedFunction(F, VF, true).empty());
return !getVectorizedFunction(F, VF).empty();
}

/// Return true if the function F has a vector equivalent with any
Expand All @@ -172,8 +170,7 @@ class TargetLibraryInfoImpl {

/// Return the name of the equivalent of F, vectorized with factor VF. If no
/// such mapping exists, return the empty string.
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF,
bool Masked) const;
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF) const;

/// Set to true iff i32 parameters to library functions should have signext
/// or zeroext attributes if they correspond to C-level int or unsigned int,
Expand Down Expand Up @@ -349,9 +346,8 @@ class TargetLibraryInfo {
bool isFunctionVectorizable(StringRef F) const {
return Impl->isFunctionVectorizable(F);
}
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF,
bool Masked = false) const {
return Impl->getVectorizedFunction(F, VF, Masked);
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF) const {
return Impl->getVectorizedFunction(F, VF);
}

/// Tests if the function is both available and a candidate for optimized code
Expand Down
86 changes: 1 addition & 85 deletions llvm/include/llvm/Analysis/VecFuncs.def
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

#define FIXED(NL) ElementCount::getFixed(NL)
#define SCALABLE(NL) ElementCount::getScalable(NL)
#define NOMASK false
#define MASKED true

#if !(defined(TLI_DEFINE_VECFUNC))
#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, NOMASK},
#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF},
#endif

#if defined(TLI_DEFINE_ACCELERATE_VECFUNCS)
Expand Down Expand Up @@ -606,91 +604,10 @@ TLI_DEFINE_VECFUNC( "llvm.tanh.f32", "_ZGVnN4v_tanhf", FIXED(4))
TLI_DEFINE_VECFUNC( "tgammaf", "_ZGVnN4v_tgammaf", FIXED(4))
TLI_DEFINE_VECFUNC( "llvm.tgamma.f32", "_ZGVnN4v_tgammaf", FIXED(4))

#elif defined(TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS)

TLI_DEFINE_VECFUNC("acos", "_ZGVsMxv_acos", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("acosf", "_ZGVsMxv_acosf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("asin", "_ZGVsMxv_asin", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("asinf", "_ZGVsMxv_asinf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("atan", "_ZGVsMxv_atan", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("atanf", "_ZGVsMxv_atanf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("atan2", "_ZGVsMxvv_atan2", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("atan2f", "_ZGVsMxvv_atan2f", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("atanh", "_ZGVsMxv_atanh", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("atanhf", "_ZGVsMxv_atanhf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("cos", "_ZGVsMxv_cos", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("cosf", "_ZGVsMxv_cosf", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.cos.f64", "_ZGVsMxv_cos", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.cos.f32", "_ZGVsMxv_cosf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("cosh", "_ZGVsMxv_cosh", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("coshf", "_ZGVsMxv_coshf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("exp", "_ZGVsMxv_exp", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("expf", "_ZGVsMxv_expf", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.exp.f64", "_ZGVsMxv_exp", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.exp.f32", "_ZGVsMxv_expf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("exp2", "_ZGVsMxv_exp2", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("exp2f", "_ZGVsMxv_exp2f", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.exp2.f64", "_ZGVsMxv_exp2", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.exp2.f32", "_ZGVsMxv_exp2f", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("exp10", "_ZGVsMxv_exp10", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("exp10f", "_ZGVsMxv_exp10f", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("lgamma", "_ZGVsMxv_lgamma", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("lgammaf", "_ZGVsMxv_lgammaf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("log", "_ZGVsMxv_log", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("logf", "_ZGVsMxv_logf", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.log.f64", "_ZGVsMxv_log", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.log.f32", "_ZGVsMxv_logf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("log10", "_ZGVsMxv_log10", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("log10f", "_ZGVsMxv_log10f", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.log10.f64", "_ZGVsMxv_log10", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.log10.f32", "_ZGVsMxv_log10f", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("pow", "_ZGVsMxvv_pow", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("powf", "_ZGVsMxvv_powf", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.pow.f64", "_ZGVsMxvv_pow", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.pow.f32", "_ZGVsMxvv_powf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("sin", "_ZGVsMxv_sin", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("sinf", "_ZGVsMxv_sinf", SCALABLE(4), MASKED)
TLI_DEFINE_VECFUNC("llvm.sin.f64", "_ZGVsMxv_sin", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("llvm.sin.f32", "_ZGVsMxv_sinf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("sinh", "_ZGVsMxv_sinh", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("sinhf", "_ZGVsMxv_sinhf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("sqrt", "_ZGVsMxv_sqrt", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("sqrtf", "_ZGVsMxv_sqrtf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("tan", "_ZGVsMxv_tan", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("tanf", "_ZGVsMxv_tanf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("tanh", "_ZGVsMxv_tanh", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("tanhf", "_ZGVsMxv_tanhf", SCALABLE(4), MASKED)

TLI_DEFINE_VECFUNC("tgamma", "_ZGVsMxv_tgamma", SCALABLE(2), MASKED)
TLI_DEFINE_VECFUNC("tgammaf", "_ZGVsMxv_tgammaf", SCALABLE(4), MASKED)

#else
#error "Must choose which vector library functions are to be defined."
#endif

#undef MASKED
#undef NOMASK
#undef SCALABLE
#undef FIXED

#undef TLI_DEFINE_VECFUNC
#undef TLI_DEFINE_ACCELERATE_VECFUNCS
#undef TLI_DEFINE_DARWIN_LIBSYSTEM_M_VECFUNCS
Expand All @@ -699,5 +616,4 @@ TLI_DEFINE_VECFUNC("tgammaf", "_ZGVsMxv_tgammaf", SCALABLE(4), MASKED)
#undef TLI_DEFINE_SVML_VECFUNCS
#undef TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
#undef TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
#undef TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
#undef TLI_DEFINE_MASSV_VECFUNCS_NAMES
5 changes: 2 additions & 3 deletions llvm/include/llvm/Analysis/VectorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,15 @@ std::optional<VFInfo> tryDemangleForVFABI(StringRef MangledName,
/// where:
///
/// <isa> = "_LLVM_"
/// <mask> = "M" if masked, "N" if no mask.
/// <mask> = "N". Note: TLI does not support masked interfaces.
/// <vlen> = Number of concurrent lanes, stored in the `VectorizationFactor`
/// field of the `VecDesc` struct. If the number of lanes is scalable
/// then 'x' is printed instead.
/// <vparams> = "v", as many as are the numArgs.
/// <scalarname> = the name of the scalar function.
/// <vectorname> = the name of the vector function.
std::string mangleTLIVectorName(StringRef VectorName, StringRef ScalarName,
unsigned numArgs, ElementCount VF,
bool Masked = false);
unsigned numArgs, ElementCount VF);

/// Retrieve the `VFParamKind` from a string token.
VFParamKind getVFParamKindFromString(const StringRef Token);
Expand Down
16 changes: 4 additions & 12 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,17 +1181,10 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
case SLEEFGNUABI: {
const VecDesc VecFuncs_VF2[] = {
#define TLI_DEFINE_SLEEFGNUABI_VF2_VECFUNCS
#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, /* MASK = */ false},
#include "llvm/Analysis/VecFuncs.def"
};
const VecDesc VecFuncs_VF4[] = {
#define TLI_DEFINE_SLEEFGNUABI_VF4_VECFUNCS
#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF) {SCAL, VEC, VF, /* MASK = */ false},
#include "llvm/Analysis/VecFuncs.def"
};
const VecDesc VecFuncs_VFScalable[] = {
#define TLI_DEFINE_SLEEFGNUABI_SCALABLE_VECFUNCS
#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, MASK) {SCAL, VEC, VF, MASK},
#include "llvm/Analysis/VecFuncs.def"
};

Expand All @@ -1202,7 +1195,6 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
case llvm::Triple::aarch64_be:
addVectorizableFunctions(VecFuncs_VF2);
addVectorizableFunctions(VecFuncs_VF4);
addVectorizableFunctions(VecFuncs_VFScalable);
break;
}
break;
Expand All @@ -1222,16 +1214,16 @@ bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
return I != VectorDescs.end() && StringRef(I->ScalarFnName) == funcName;
}

StringRef TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
const ElementCount &VF,
bool Masked) const {
StringRef
TargetLibraryInfoImpl::getVectorizedFunction(StringRef F,
const ElementCount &VF) const {
F = sanitizeFunctionName(F);
if (F.empty())
return F;
std::vector<VecDesc>::const_iterator I =
llvm::lower_bound(VectorDescs, F, compareWithScalarFnName);
while (I != VectorDescs.end() && StringRef(I->ScalarFnName) == F) {
if ((I->VectorizationFactor == VF) && (I->Masked == Masked))
if (I->VectorizationFactor == VF)
return I->VectorFnName;
++I;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/VectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1529,10 +1529,10 @@ void InterleaveGroup<Instruction>::addMetadata(Instruction *NewInst) const {

std::string VFABI::mangleTLIVectorName(StringRef VectorName,
StringRef ScalarName, unsigned numArgs,
ElementCount VF, bool Masked) {
ElementCount VF) {
SmallString<256> Buffer;
llvm::raw_svector_ostream Out(Buffer);
Out << "_ZGV" << VFABI::_LLVM_ << (Masked ? "M" : "N");
Out << "_ZGV" << VFABI::_LLVM_ << "N";
if (VF.isScalable())
Out << 'x';
else
Expand Down
28 changes: 12 additions & 16 deletions llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ STATISTIC(NumCompUsedAdded,
/// CI (other than void) need to be widened to a VectorType of VF
/// lanes.
static void addVariantDeclaration(CallInst &CI, const ElementCount &VF,
bool Predicate, const StringRef VFName) {
const StringRef VFName) {
Module *M = CI.getModule();

// Add function declaration.
Expand All @@ -50,8 +50,6 @@ static void addVariantDeclaration(CallInst &CI, const ElementCount &VF,
Tys.push_back(ToVectorTy(ArgOperand->getType(), VF));
assert(!CI.getFunctionType()->isVarArg() &&
"VarArg functions are not supported.");
if (Predicate)
Tys.push_back(ToVectorTy(Type::getInt1Ty(RetTy->getContext()), VF));
FunctionType *FTy = FunctionType::get(RetTy, Tys, /*isVarArg=*/false);
Function *VectorF =
Function::Create(FTy, Function::ExternalLinkage, VFName, M);
Expand Down Expand Up @@ -91,35 +89,33 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) {
const SetVector<StringRef> OriginalSetOfMappings(Mappings.begin(),
Mappings.end());

auto AddVariantDecl = [&](const ElementCount &VF, bool Predicate) {
auto AddVariantDecl = [&](const ElementCount &VF) {
const std::string TLIName =
std::string(TLI.getVectorizedFunction(ScalarName, VF, Predicate));
std::string(TLI.getVectorizedFunction(ScalarName, VF));
if (!TLIName.empty()) {
std::string MangledName = VFABI::mangleTLIVectorName(
TLIName, ScalarName, CI.arg_size(), VF, Predicate);
std::string MangledName =
VFABI::mangleTLIVectorName(TLIName, ScalarName, CI.arg_size(), VF);
if (!OriginalSetOfMappings.count(MangledName)) {
Mappings.push_back(MangledName);
++NumCallInjected;
}
Function *VariantF = M->getFunction(TLIName);
if (!VariantF)
addVariantDeclaration(CI, VF, Predicate, TLIName);
addVariantDeclaration(CI, VF, TLIName);
}
};

// All VFs in the TLI are powers of 2.
ElementCount WidestFixedVF, WidestScalableVF;
TLI.getWidestVF(ScalarName, WidestFixedVF, WidestScalableVF);

for (bool Predicated : {false, true}) {
for (ElementCount VF = ElementCount::getFixed(2);
ElementCount::isKnownLE(VF, WidestFixedVF); VF *= 2)
AddVariantDecl(VF, Predicated);
for (ElementCount VF = ElementCount::getFixed(2);
ElementCount::isKnownLE(VF, WidestFixedVF); VF *= 2)
AddVariantDecl(VF);

for (ElementCount VF = ElementCount::getScalable(2);
ElementCount::isKnownLE(VF, WidestScalableVF); VF *= 2)
AddVariantDecl(VF, Predicated);
}
// TODO: Add scalable variants once we're able to test them.
assert(WidestScalableVF.isZero() &&
"Scalable vector mappings not yet supported");

VFABI::setVectorVariantNames(&CI, Mappings);
}
Expand Down

0 comments on commit f8f1909

Please sign in to comment.