Skip to content

Commit cb1228f

Browse files
authored
RuntimeLibcalls: Return StringRef for libcall names (#153209)
Does not yet fully propagate this down into the TargetLowering uses, many of which are relying on null checks on the returned value.
1 parent 0226e94 commit cb1228f

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

llvm/benchmarks/RuntimeLibcalls.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ static constexpr unsigned MaxFuncNameSize = 53;
2222
static std::vector<StringRef> getLibcallNameStringRefs() {
2323
std::vector<StringRef> Names(RTLIB::NumLibcallImpls);
2424
// Keep the strlens on the StringRef construction out of the benchmark loop.
25-
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls()) {
26-
const char *Name = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
27-
Names[LC] = StringRef(Name);
28-
}
25+
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls())
26+
Names[LC] = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
2927

3028
return Names;
3129
}

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,15 +3552,19 @@ class LLVM_ABI TargetLoweringBase {
35523552

35533553
/// Get the libcall routine name for the specified libcall.
35543554
const char *getLibcallName(RTLIB::Libcall Call) const {
3555-
return Libcalls.getLibcallName(Call);
3555+
// FIXME: Return StringRef
3556+
return Libcalls.getLibcallName(Call).data();
35563557
}
35573558

35583559
/// Get the libcall routine name for the specified libcall implementation
3559-
const char *getLibcallImplName(RTLIB::LibcallImpl Call) const {
3560-
return Libcalls.getLibcallImplName(Call);
3560+
static StringRef getLibcallImplName(RTLIB::LibcallImpl Call) {
3561+
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Call);
35613562
}
35623563

3563-
const char *getMemcpyName() const { return Libcalls.getMemcpyName(); }
3564+
const char *getMemcpyName() const {
3565+
// FIXME: Return StringRef
3566+
return Libcalls.getMemcpyName().data();
3567+
}
35643568

35653569
/// Get the comparison predicate that's to be used to test the result of the
35663570
/// comparison libcall against zero. This should only be used with

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,15 @@ struct RuntimeLibcallsInfo {
7777

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

8484
/// Get the libcall routine name for the specified libcall implementation.
85-
// FIXME: Change to return StringRef
86-
static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
85+
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
8786
if (CallImpl == RTLIB::Unsupported)
88-
return nullptr;
89-
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
90-
.data();
87+
return StringRef();
88+
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]];
9189
}
9290

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

120118
/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
121119
/// unsupported.
122-
const char *getMemcpyName() const {
123-
if (const char *Memcpy = getLibcallName(RTLIB::MEMCPY))
124-
return Memcpy;
120+
StringRef getMemcpyName() const {
121+
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
122+
if (Memcpy != RTLIB::Unsupported)
123+
return getLibcallImplName(Memcpy);
125124

126125
// Fallback to memmove if memcpy isn't available.
127126
return getLibcallName(RTLIB::MEMMOVE);

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static bool lowerObjCCall(Function &F, RTLIB::LibcallImpl NewFn,
145145

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

150150
// If we haven't already looked up this function, check to see if the
151151
// program already contains a function with this name.

llvm/lib/LTO/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
14221422

14231423
for (RTLIB::LibcallImpl Impl : LibcallImpls) {
14241424
if (Impl != RTLIB::Unsupported)
1425-
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl));
1425+
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl).data());
14261426
}
14271427

14281428
return LibcallSymbols;

llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ struct StaticLibcallNameMap {
533533
// different libcalls.
534534
RTLIB::RuntimeLibcallsInfo RTCI(TT);
535535
for (RTLIB::Libcall LC : RTLIB::libcalls()) {
536-
const char *NameLibcall = RTCI.getLibcallName(LC);
537-
if (NameLibcall != nullptr &&
536+
StringRef NameLibcall = RTCI.getLibcallName(LC);
537+
if (!NameLibcall.empty() &&
538538
getRuntimeLibcallSignatures().Table[LC] != unsupported) {
539539
assert(!Map.contains(NameLibcall) &&
540540
"duplicate libcall names in name map");

llvm/lib/Transforms/Utils/DeclareRuntimeLibcalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ PreservedAnalyses DeclareRuntimeLibcallsPass::run(Module &M,
3030
FunctionType *FuncTy =
3131
FunctionType::get(Type::getVoidTy(Ctx), {}, /*IsVarArgs=*/true);
3232

33-
const char *FuncName = RTLCI.getLibcallImplName(Impl);
33+
StringRef FuncName = RTLCI.getLibcallImplName(Impl);
3434
M.getOrInsertFunction(FuncName, FuncTy);
3535
}
3636

llvm/unittests/IR/RuntimeLibcallsTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(RuntimeLibcallsTest, LibcallImplByName) {
2323
RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName("unsupported").empty());
2424

2525
for (RTLIB::LibcallImpl LC : RTLIB::libcall_impls()) {
26-
const char *Name = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
26+
StringRef Name = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LC);
2727
EXPECT_TRUE(is_contained(
2828
RTLIB::RuntimeLibcallsInfo::lookupLibcallImplName(Name), LC));
2929
}

0 commit comments

Comments
 (0)