[lld] r265235 - Move code to initialize LLVM to one place.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 11:18:45 PDT 2016


Author: ruiu
Date: Sat Apr  2 13:18:44 2016
New Revision: 265235

URL: http://llvm.org/viewvc/llvm-project?rev=265235&view=rev
Log:
Move code to initialize LLVM to one place.

Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=265235&r1=265234&r2=265235&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Apr  2 13:18:44 2016
@@ -142,6 +142,24 @@ void LinkerDriver::addLibrary(StringRef
     addFile(Path);
 }
 
+// This function is called on startup. We need this for LTO since
+// LTO calls LLVM functions to compile bitcode files to native code.
+// Technically this can be delayed until we read bitcode files, but
+// we don't bother to do lazily because the initialization is fast.
+static void initLLVM(opt::InputArgList &Args) {
+  InitializeAllTargets();
+  InitializeAllTargetMCs();
+  InitializeAllAsmPrinters();
+  InitializeAllAsmParsers();
+
+  // Parse and evaluate -mllvm options.
+  std::vector<const char *> V;
+  V.push_back("lld (LLVM option parsing)");
+  for (auto *Arg : Args.filtered(OPT_mllvm))
+    V.push_back(Arg->getValue());
+  cl::ParseCommandLineOptions(V.size(), V.data());
+}
+
 // Some command line options or some combinations of them are not allowed.
 // This function checks for such errors.
 static void checkOptions(opt::InputArgList &Args) {
@@ -205,6 +223,7 @@ void LinkerDriver::main(ArrayRef<const c
     return;
   }
 
+  initLLVM(Args);
   readConfigs(Args);
   createFiles(Args);
   checkOptions(Args);
@@ -308,12 +327,6 @@ void LinkerDriver::readConfigs(opt::Inpu
 
   for (auto *Arg : Args.filtered(OPT_undefined))
     Config->Undefined.push_back(Arg->getValue());
-
-  std::vector<const char *> Argv;
-  Argv.push_back("lld (LLVM option parsing)");
-  for (auto *Arg : Args.filtered(OPT_mllvm))
-    Argv.push_back(Arg->getValue());
-  cl::ParseCommandLineOptions(Argv.size(), Argv.data());
 }
 
 void LinkerDriver::createFiles(opt::InputArgList &Args) {
@@ -360,12 +373,6 @@ template <class ELFT> static void initSy
 }
 
 template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
-  // For LTO
-  InitializeAllTargets();
-  InitializeAllTargetMCs();
-  InitializeAllAsmPrinters();
-  InitializeAllAsmParsers();
-
   initSymbols<ELFT>();
 
   SymbolTable<ELFT> Symtab;




More information about the llvm-commits mailing list