From fa38810646b59046b836a1c258627f75eb628f2c Mon Sep 17 00:00:00 2001 From: David Sherwood Date: Mon, 8 Feb 2021 17:16:03 +0000 Subject: [PATCH] [Analysis] Change VFABI::mangleTLIVectorName to use ElementCount Adds support for mangling TLI vector names for scalable vectors. Differential Revision: https://reviews.llvm.org/D96338 --- include/llvm/Analysis/VectorUtils.h | 5 +++-- lib/Analysis/VectorUtils.cpp | 8 ++++++-- lib/Transforms/Utils/InjectTLIMappings.cpp | 3 ++- unittests/Analysis/VectorFunctionABITest.cpp | 11 ++++++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/llvm/Analysis/VectorUtils.h b/include/llvm/Analysis/VectorUtils.h index 26cb0e456ed..181c42c2a09 100644 --- a/include/llvm/Analysis/VectorUtils.h +++ b/include/llvm/Analysis/VectorUtils.h @@ -186,12 +186,13 @@ Optional tryDemangleForVFABI(StringRef MangledName, const Module &M); /// = "_LLVM_" /// = "N". Note: TLI does not support masked interfaces. /// = Number of concurrent lanes, stored in the `VectorizationFactor` -/// field of the `VecDesc` struct. +/// field of the `VecDesc` struct. If the number of lanes is scalable +/// then 'x' is printed instead. /// = "v", as many as are the numArgs. /// = the name of the scalar function. /// = the name of the vector function. std::string mangleTLIVectorName(StringRef VectorName, StringRef ScalarName, - unsigned numArgs, unsigned VF); + unsigned numArgs, ElementCount VF); /// Retrieve the `VFParamKind` from a string token. VFParamKind getVFParamKindFromString(const StringRef Token); diff --git a/lib/Analysis/VectorUtils.cpp b/lib/Analysis/VectorUtils.cpp index 9a4c96b6f7c..a6070b67fc1 100644 --- a/lib/Analysis/VectorUtils.cpp +++ b/lib/Analysis/VectorUtils.cpp @@ -1300,10 +1300,14 @@ void InterleaveGroup::addMetadata(Instruction *NewInst) const { std::string VFABI::mangleTLIVectorName(StringRef VectorName, StringRef ScalarName, unsigned numArgs, - unsigned VF) { + ElementCount VF) { SmallString<256> Buffer; llvm::raw_svector_ostream Out(Buffer); - Out << "_ZGV" << VFABI::_LLVM_ << "N" << VF; + Out << "_ZGV" << VFABI::_LLVM_ << "N"; + if (VF.isScalable()) + Out << 'x'; + else + Out << VF.getFixedValue(); for (unsigned I = 0; I < numArgs; ++I) Out << "v"; Out << "_" << ScalarName << "(" << VectorName << ")"; diff --git a/lib/Transforms/Utils/InjectTLIMappings.cpp b/lib/Transforms/Utils/InjectTLIMappings.cpp index a2b72e4e7f0..42c49b7f5dc 100644 --- a/lib/Transforms/Utils/InjectTLIMappings.cpp +++ b/lib/Transforms/Utils/InjectTLIMappings.cpp @@ -96,7 +96,8 @@ static void addMappingsFromTLI(const TargetLibraryInfo &TLI, CallInst &CI) { std::string(TLI.getVectorizedFunction(ScalarName, VF)); if (!TLIName.empty()) { std::string MangledName = VFABI::mangleTLIVectorName( - TLIName, ScalarName, CI.getNumArgOperands(), VF); + TLIName, ScalarName, CI.getNumArgOperands(), + ElementCount::getFixed(VF)); if (!OriginalSetOfMappings.count(MangledName)) { Mappings.push_back(MangledName); ++NumCallInjected; diff --git a/unittests/Analysis/VectorFunctionABITest.cpp b/unittests/Analysis/VectorFunctionABITest.cpp index d1f878754cb..e0c3c16dea5 100644 --- a/unittests/Analysis/VectorFunctionABITest.cpp +++ b/unittests/Analysis/VectorFunctionABITest.cpp @@ -101,9 +101,14 @@ protected: // This test makes sure correct mangling occurs for given string. TEST_F(VFABIParserTest, ManglingVectorTLINames) { - EXPECT_EQ(VFABI::mangleTLIVectorName("vec", "scalar", 3, 4), - "_ZGV_LLVM_N4vvv_scalar(vec)"); - EXPECT_EQ(VFABI::mangleTLIVectorName("custom.call.v5", "custom.call", 1, 5), + EXPECT_EQ( + VFABI::mangleTLIVectorName("vec", "scalar", 3, ElementCount::getFixed(4)), + "_ZGV_LLVM_N4vvv_scalar(vec)"); + EXPECT_EQ(VFABI::mangleTLIVectorName("vec", "scalar", 3, + ElementCount::getScalable(4)), + "_ZGV_LLVM_Nxvvv_scalar(vec)"); + EXPECT_EQ(VFABI::mangleTLIVectorName("custom.call.v5", "custom.call", 1, + ElementCount::getFixed(5)), "_ZGV_LLVM_N5v_custom.call(custom.call.v5)"); }