]> granicus.if.org Git - llvm/commitdiff
Put "built-in" function definitions in global Used list, for LTO. (fix bug 34169)
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 24 Jul 2018 19:34:37 +0000 (19:34 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 24 Jul 2018 19:34:37 +0000 (19:34 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337847 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/RuntimeLibcalls.h
include/llvm/IR/RuntimeLibcalls.def [moved from include/llvm/CodeGen/RuntimeLibcalls.def with 100% similarity]
include/llvm/module.modulemap
lib/CodeGen/TargetLoweringBase.cpp
lib/Object/IRSymtab.cpp
lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp

index 016bef1702c4c909846da4013a9a1999e2ab693b..28567a1ce437535f37ba51b019a550271e6509d5 100644 (file)
@@ -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
   };
 
index 6fc728295f6e883c63381201e774aad3d776d641..649cdf3b0a89c846c24bb1f0809dc13fafea0022 100644 (file)
@@ -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 {
@@ -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 * } }
index 96e03388d5c14be9ff040e0c659968f0fa5102e3..43f4bad595e306c948b2bbe5d901f87d37f1aa35 100644 (file)
@@ -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)
index 51081d8b5e642e27909293795fc2764c236d435d..344d565349c09361d58f8a0101022c61ac673e3e 100644 (file)
 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() {
@@ -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;
index e5180ad7f2e933c51a7b6301ee1d8017977b0d7a..fe8a5e4c06f1aa713a8c98dcdc73627b709d5b88 100644 (file)
@@ -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) {