[lld] r285290 - Use fewer allocators.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 27 06:32:32 PDT 2016


Author: rafael
Date: Thu Oct 27 08:32:32 2016
New Revision: 285290

URL: http://llvm.org/viewvc/llvm-project?rev=285290&view=rev
Log:
Use fewer allocators.

Instead of having 3 section allocators per file, have 3 for all files.

This is a substantial performance improvement for some cases. Linking
chromium without gc speeds up by 1.065x.

This requires using _exit in fatal since we have to avoid destructing
an InputSection if fatal is called from the constructor.

Thanks to Rui for the suggestion.

Modified:
    lld/trunk/ELF/Error.cpp
    lld/trunk/ELF/Error.h
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=285290&r1=285289&r2=285290&view=diff
==============================================================================
--- lld/trunk/ELF/Error.cpp (original)
+++ lld/trunk/ELF/Error.cpp Thu Oct 27 08:32:32 2016
@@ -14,6 +14,10 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
 
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
+#include <unistd.h>
+#endif
+
 using namespace llvm;
 
 namespace lld {
@@ -43,9 +47,15 @@ void elf::error(std::error_code EC, cons
   error(Prefix + ": " + EC.message());
 }
 
+void elf::exitLld(int Val) {
+  outs().flush();
+  errs().flush();
+  _exit(Val);
+}
+
 void elf::fatal(const Twine &Msg) {
   *ErrorOS << Argv0 << ": error: " << Msg << "\n";
-  exit(1);
+  exitLld(1);
 }
 
 void elf::fatal(std::error_code EC, const Twine &Prefix) {

Modified: lld/trunk/ELF/Error.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=285290&r1=285289&r2=285290&view=diff
==============================================================================
--- lld/trunk/ELF/Error.h (original)
+++ lld/trunk/ELF/Error.h Thu Oct 27 08:32:32 2016
@@ -45,6 +45,7 @@ template <typename T> void error(const E
   error(V.getError(), Prefix);
 }
 
+LLVM_ATTRIBUTE_NORETURN void exitLld(int Val);
 LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
 LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
 

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=285290&r1=285289&r2=285290&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Oct 27 08:32:32 2016
@@ -386,7 +386,8 @@ elf::ObjectFile<ELFT>::createInputSectio
     // If -r is given, we do not interpret or apply relocation
     // but just copy relocation sections to output.
     if (Config->Relocatable)
-      return new (IAlloc.Allocate()) InputSection<ELFT>(this, &Sec, Name);
+      return new (GAlloc<ELFT>::IAlloc.Allocate())
+          InputSection<ELFT>(this, &Sec, Name);
 
     // Find the relocation target section and associate this
     // section with it.
@@ -428,11 +429,14 @@ elf::ObjectFile<ELFT>::createInputSectio
   // .eh_frame_hdr section for runtime. So we handle them with a special
   // class. For relocatable outputs, they are just passed through.
   if (Name == ".eh_frame" && !Config->Relocatable)
-    return new (EHAlloc.Allocate()) EhInputSection<ELFT>(this, &Sec, Name);
+    return new (GAlloc<ELFT>::EHAlloc.Allocate())
+        EhInputSection<ELFT>(this, &Sec, Name);
 
   if (shouldMerge(Sec))
-    return new (MAlloc.Allocate()) MergeInputSection<ELFT>(this, &Sec, Name);
-  return new (IAlloc.Allocate()) InputSection<ELFT>(this, &Sec, Name);
+    return new (GAlloc<ELFT>::MAlloc.Allocate())
+        MergeInputSection<ELFT>(this, &Sec, Name);
+  return new (GAlloc<ELFT>::IAlloc.Allocate())
+      InputSection<ELFT>(this, &Sec, Name);
 }
 
 template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=285290&r1=285289&r2=285290&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Oct 27 08:32:32 2016
@@ -38,6 +38,21 @@ class InputFile;
 namespace lld {
 namespace elf {
 
+template <class ELFT> struct GAlloc {
+  static llvm::SpecificBumpPtrAllocator<InputSection<ELFT>> IAlloc;
+  static llvm::SpecificBumpPtrAllocator<MergeInputSection<ELFT>> MAlloc;
+  static llvm::SpecificBumpPtrAllocator<EhInputSection<ELFT>> EHAlloc;
+};
+
+template <class ELFT>
+llvm::SpecificBumpPtrAllocator<InputSection<ELFT>> GAlloc<ELFT>::IAlloc;
+
+template <class ELFT>
+llvm::SpecificBumpPtrAllocator<MergeInputSection<ELFT>> GAlloc<ELFT>::MAlloc;
+
+template <class ELFT>
+llvm::SpecificBumpPtrAllocator<EhInputSection<ELFT>> GAlloc<ELFT>::EHAlloc;
+
 using llvm::object::Archive;
 
 class InputFile;
@@ -233,9 +248,6 @@ private:
   // MIPS .MIPS.abiflags section defined by this file.
   std::unique_ptr<MipsAbiFlagsInputSection<ELFT>> MipsAbiFlags;
 
-  llvm::SpecificBumpPtrAllocator<InputSection<ELFT>> IAlloc;
-  llvm::SpecificBumpPtrAllocator<MergeInputSection<ELFT>> MAlloc;
-  llvm::SpecificBumpPtrAllocator<EhInputSection<ELFT>> EHAlloc;
   std::unique_ptr<DIHelper<ELFT>> DIH;
 };
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=285290&r1=285289&r2=285290&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Oct 27 08:32:32 2016
@@ -23,10 +23,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include <climits>
 
-#if !defined(_MSC_VER) && !defined(__MINGW32__)
-#include <unistd.h>
-#endif
-
 using namespace llvm;
 using namespace llvm::ELF;
 using namespace llvm::object;
@@ -324,9 +320,7 @@ template <class ELFT> void Writer<ELFT>:
     // Flush the output streams and exit immediately.  A full shutdown is a good
     // test that we are keeping track of all allocated memory, but actually
     // freeing it is a waste of time in a regular linker run.
-    outs().flush();
-    errs().flush();
-    _exit(0);
+    exitLld(0);
   }
 }
 




More information about the llvm-commits mailing list