Skip to content

RuntimeLibcalls: Return StringRef for libcall names #153209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions llvm/benchmarks/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ static constexpr unsigned MaxFuncNameSize = 53;
static std::vector<StringRef> getLibcallNameStringRefs() {
std::vector<StringRef> Names(RTLIB::NumLibcallImpls);
// Keep the strlens on the StringRef construction out of the benchmark loop.
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls()) {
const char *Name = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
Names[LC] = StringRef(Name);
}
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
Names[LC] = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);

return Names;
}
Expand Down
12 changes: 8 additions & 4 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -3552,15 +3552,19 @@ class LLVM_ABI TargetLoweringBase {

/// Get the libcall routine name for the specified libcall.
const char *getLibcallName(RTLIB::Libcall Call) const {
return Libcalls.getLibcallName(Call);
// FIXME: Return StringRef
return Libcalls.getLibcallName(Call).data();
}

/// Get the libcall routine name for the specified libcall implementation
const char *getLibcallImplName(RTLIB::LibcallImpl Call) const {
return Libcalls.getLibcallImplName(Call);
static StringRef getLibcallImplName(RTLIB::LibcallImpl Call) {
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Call);
}

const char *getMemcpyName() const { return Libcalls.getMemcpyName(); }
const char *getMemcpyName() const {
// FIXME: Return StringRef
return Libcalls.getMemcpyName().data();
}

/// Get the comparison predicate that's to be used to test the result of the
/// comparison libcall against zero. This should only be used with
Expand Down
17 changes: 8 additions & 9 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,15 @@ struct RuntimeLibcallsInfo {

/// Get the libcall routine name for the specified libcall.
// FIXME: This should be removed. Only LibcallImpl should have a name.
const char *getLibcallName(RTLIB::Libcall Call) const {
StringRef getLibcallName(RTLIB::Libcall Call) const {
return getLibcallImplName(LibcallImpls[Call]);
}

/// Get the libcall routine name for the specified libcall implementation.
// FIXME: Change to return StringRef
static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
if (CallImpl == RTLIB::Unsupported)
return nullptr;
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
.data();
return StringRef();
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]];
}

/// Return the lowering's selection of implementation call for \p Call
Expand Down Expand Up @@ -119,9 +117,10 @@ struct RuntimeLibcallsInfo {

/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
/// unsupported.
const char *getMemcpyName() const {
if (const char *Memcpy = getLibcallName(RTLIB::MEMCPY))
return Memcpy;
StringRef getMemcpyName() const {
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
if (Memcpy != RTLIB::Unsupported)
return getLibcallImplName(Memcpy);

// Fallback to memmove if memcpy isn't available.
return getLibcallName(RTLIB::MEMMOVE);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static bool lowerObjCCall(Function &F, RTLIB::LibcallImpl NewFn,

// FIXME: When RuntimeLibcalls is an analysis, check if the function is really
// supported, and go through RTLIB::Libcall.
const char *NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);
StringRef NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);

// If we haven't already looked up this function, check to see if the
// program already contains a function with this name.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {

for (RTLIB::LibcallImpl Impl : LibcallImpls) {
if (Impl != RTLIB::Unsupported)
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl));
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl).data());
}

return LibcallSymbols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ struct StaticLibcallNameMap {
// different libcalls.
RTLIB::RuntimeLibcallsInfo RTCI(TT);
for (RTLIB::Libcall LC : RTLIB::libcalls()) {
const char *NameLibcall = RTCI.getLibcallName(LC);
if (NameLibcall != nullptr &&
StringRef NameLibcall = RTCI.getLibcallName(LC);
if (!NameLibcall.empty() &&
getRuntimeLibcallSignatures().Table[LC] != unsupported) {
assert(!Map.contains(NameLibcall) &&
"duplicate libcall names in name map");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M,
FunctionType *FuncTy =
FunctionType::get(Type::getVoidTy(Ctx), {}, /*IsVarArgs=*/true);

const char *FuncName = RTLCI.getLibcallImplName(Impl);
StringRef FuncName = RTLCI.getLibcallImplName(Impl);
M.getOrInsertFunction(FuncName, FuncTy);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/IR/RuntimeLibcallsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST(RuntimeLibcallsTest, LibcallImplByName) {
RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName("unsupported").empty());

for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls()) {
const char *Name = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
StringRef Name = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
EXPECT_TRUE(is_contained(
RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName(Name), LC));
}
Expand Down
Loading