Skip to content

Commit

Permalink
Put "built-in" function definitions in global Used list, for LTO. (fi…
Browse files Browse the repository at this point in the history
…x 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
  • Loading branch information
pcc committed Jul 24, 2018
1 parent c9313a9 commit e06bac4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace RTLIB {
///
enum Libcall {
#define HANDLE_LIBCALL(code, name) code,
#include "RuntimeLibcalls.def"
#include "llvm/IR/RuntimeLibcalls.def"
#undef HANDLE_LIBCALL
};

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion llvm/include/llvm/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module LLVM_Backend {
// These are intended for (repeated) textual inclusion.
textual header "CodeGen/CommandFlags.inc"
textual header "CodeGen/DIEValue.def"
textual header "CodeGen/RuntimeLibcalls.def"
}

module Target {
Expand Down Expand Up @@ -222,6 +221,7 @@ module LLVM_IR {
textual header "IR/Instruction.def"
textual header "IR/Metadata.def"
textual header "IR/Value.def"
textual header "IR/RuntimeLibcalls.def"
}

module LLVM_IRReader { requires cplusplus umbrella "IRReader" module * { export * } }
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static cl::opt<int> MinPercentageForPredictableBranch(
void TargetLoweringBase::InitLibcalls(const Triple &TT) {
#define HANDLE_LIBCALL(code, name) \
setLibcallName(RTLIB::code, name);
#include "llvm/CodeGen/RuntimeLibcalls.def"
#include "llvm/IR/RuntimeLibcalls.def"
#undef HANDLE_LIBCALL
// Initialize calling conventions to their default.
for (int LC = 0; LC < RTLIB::UNKNOWN_LIBCALL; ++LC)
Expand Down
14 changes: 13 additions & 1 deletion llvm/lib/Object/IRSymtab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
using namespace llvm;
using namespace irsymtab;

static const char *LibcallRoutineNames[] = {
#define HANDLE_LIBCALL(code, name) name,
#include "llvm/IR/RuntimeLibcalls.def"
#undef HANDLE_LIBCALL
};

namespace {

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

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

if (Used.count(GV))
bool IsBuiltinFunc = false;

for (const char *LibcallName : LibcallRoutineNames)
if (GV->getName() == LibcallName)
IsBuiltinFunc = true;

if (Used.count(GV) || IsBuiltinFunc)
Sym.Flags |= 1 << storage::Symbol::FB_used;
if (GV->isThreadLocal())
Sym.Flags |= 1 << storage::Symbol::FB_tls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ struct StaticLibcallNameMap {
StaticLibcallNameMap() {
static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = {
#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code},
#include "llvm/CodeGen/RuntimeLibcalls.def"
#include "llvm/IR/RuntimeLibcalls.def"
#undef HANDLE_LIBCALL
};
for (const auto &NameLibcall : NameLibcalls) {
Expand Down

0 comments on commit e06bac4

Please sign in to comment.