From 1fc5d488778ba0cf4509b31e8882ba8863f55eda Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 2 Apr 2016 18:18:44 +0000 Subject: [PATCH] Move code to initialize LLVM to one place. llvm-svn: 265235 --- lld/ELF/Driver.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 756d84e363f0..a825d6b617dd 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -142,6 +142,24 @@ void LinkerDriver::addLibrary(StringRef Name) { 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 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 ArgsArr) { return; } + initLLVM(Args); readConfigs(Args); createFiles(Args); checkOptions(Args); @@ -308,12 +327,6 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { for (auto *Arg : Args.filtered(OPT_undefined)) Config->Undefined.push_back(Arg->getValue()); - - std::vector 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 static void initSymbols() { } template void LinkerDriver::link(opt::InputArgList &Args) { - // For LTO - InitializeAllTargets(); - InitializeAllTargetMCs(); - InitializeAllAsmPrinters(); - InitializeAllAsmParsers(); - initSymbols(); SymbolTable Symtab;