Skip to content

Commit e06bac4

Browse files
committed
Put "built-in" function definitions in global Used list, for LTO. (fix bug 34169)
When building with LTO, builtin functions that are defined but whose calls have not been inserted yet, get internalized. The Global Dead Code Elimination phase in the new LTO implementation then removes these function definitions. Later optimizations add calls to those functions, and the linker then dies complaining that there are no definitions. This CL fixes the new LTO implementation to check if a function is builtin, and if so, to not internalize (and later DCE) the function. As part of this fix I needed to move the RuntimeLibcalls.{def,h} files from the CodeGen subidrectory to the IR subdirectory. I have updated all the files that accessed those two files to access their new location. Fixes PR34169 Patch by Caroline Tice! Differential Revision: https://reviews.llvm.org/D49434 llvm-svn: 337847
1 parent c9313a9 commit e06bac4

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

llvm/include/llvm/CodeGen/RuntimeLibcalls.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace RTLIB {
2929
///
3030
enum Libcall {
3131
#define HANDLE_LIBCALL(code, name) code,
32-
#include "RuntimeLibcalls.def"
32+
#include "llvm/IR/RuntimeLibcalls.def"
3333
#undef HANDLE_LIBCALL
3434
};
3535

llvm/include/llvm/module.modulemap

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module LLVM_Backend {
2626
// These are intended for (repeated) textual inclusion.
2727
textual header "CodeGen/CommandFlags.inc"
2828
textual header "CodeGen/DIEValue.def"
29-
textual header "CodeGen/RuntimeLibcalls.def"
3029
}
3130

3231
module Target {
@@ -222,6 +221,7 @@ module LLVM_IR {
222221
textual header "IR/Instruction.def"
223222
textual header "IR/Metadata.def"
224223
textual header "IR/Value.def"
224+
textual header "IR/RuntimeLibcalls.def"
225225
}
226226

227227
module LLVM_IRReader { requires cplusplus umbrella "IRReader" module * { export * } }

llvm/lib/CodeGen/TargetLoweringBase.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static cl::opt<int> MinPercentageForPredictableBranch(
118118
void TargetLoweringBase::InitLibcalls(const Triple &TT) {
119119
#define HANDLE_LIBCALL(code, name) \
120120
setLibcallName(RTLIB::code, name);
121-
#include "llvm/CodeGen/RuntimeLibcalls.def"
121+
#include "llvm/IR/RuntimeLibcalls.def"
122122
#undef HANDLE_LIBCALL
123123
// Initialize calling conventions to their default.
124124
for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)

llvm/lib/Object/IRSymtab.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
using namespace llvm;
4343
using namespace irsymtab;
4444

45+
static const char *LibcallRoutineNames[] = {
46+
#define HANDLE_LIBCALL(code, name) name,
47+
#include "llvm/IR/RuntimeLibcalls.def"
48+
#undef HANDLE_LIBCALL
49+
};
50+
4551
namespace {
4652

4753
const char *getExpectedProducerName() {
@@ -226,7 +232,13 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
226232

227233
setStr(Sym.IRName, GV->getName());
228234

229-
if (Used.count(GV))
235+
bool IsBuiltinFunc = false;
236+
237+
for (const char *LibcallName : LibcallRoutineNames)
238+
if (GV->getName() == LibcallName)
239+
IsBuiltinFunc = true;
240+
241+
if (Used.count(GV) || IsBuiltinFunc)
230242
Sym.Flags |= 1 << storage::Symbol::FB_used;
231243
if (GV->isThreadLocal())
232244
Sym.Flags |= 1 << storage::Symbol::FB_tls;

llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ struct StaticLibcallNameMap {
470470
StaticLibcallNameMap() {
471471
static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = {
472472
#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code},
473-
#include "llvm/CodeGen/RuntimeLibcalls.def"
473+
#include "llvm/IR/RuntimeLibcalls.def"
474474
#undef HANDLE_LIBCALL
475475
};
476476
for (const auto &NameLibcall : NameLibcalls) {

0 commit comments

Comments
 (0)