diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:03:39 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:03:39 +0000 |
commit | d2d3ebb81992e107edf95c1c136d7a342d9b1418 (patch) | |
tree | bb1af8fff2b1400cf240e3b2532a1e5d22a121da /ELF/LTO.cpp | |
parent | 16787c9ce0b96aaa669d7fab3a495916b35ce758 (diff) | |
download | src-test2-d2d3ebb81992e107edf95c1c136d7a342d9b1418.tar.gz src-test2-d2d3ebb81992e107edf95c1c136d7a342d9b1418.zip |
Notes
Diffstat (limited to 'ELF/LTO.cpp')
-rw-r--r-- | ELF/LTO.cpp | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/ELF/LTO.cpp b/ELF/LTO.cpp index b342b6195f1d..dd435173101a 100644 --- a/ELF/LTO.cpp +++ b/ELF/LTO.cpp @@ -12,12 +12,13 @@ #include "Error.h" #include "InputFiles.h" #include "Symbols.h" +#include "lld/Core/TargetOptionsCommandFlags.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" -#include "llvm/CodeGen/CommandFlags.h" #include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/LTO/Caching.h" #include "llvm/LTO/Config.h" #include "llvm/LTO/LTO.h" #include "llvm/Object/SymbolicFile.h" @@ -46,7 +47,7 @@ static void saveBuffer(StringRef Buffer, const Twine &Path) { std::error_code EC; raw_fd_ostream OS(Path.str(), EC, sys::fs::OpenFlags::F_None); if (EC) - error(EC, "cannot create " + Path); + error("cannot create " + Path + ": " + EC.message()); OS << Buffer; } @@ -73,6 +74,7 @@ static std::unique_ptr<lto::LTO> createLTO() { Conf.Options.RelaxELFRelocations = true; Conf.RelocModel = Config->Pic ? Reloc::PIC_ : Reloc::Static; + Conf.CodeModel = GetCodeModelFromCMModel(); Conf.DisableVerify = Config->DisableVerify; Conf.DiagHandler = diagnosticHandler; Conf.OptLevel = Config->LTOO; @@ -81,6 +83,10 @@ static std::unique_ptr<lto::LTO> createLTO() { Conf.OptPipeline = Config->LTONewPmPasses; Conf.AAPipeline = Config->LTOAAPipeline; + // Set up optimization remarks if we've been asked to. + Conf.RemarksFilename = Config->OptRemarksFilename; + Conf.RemarksWithHotness = Config->OptRemarksWithHotness; + if (Config->SaveTemps) checkError(Conf.addSaveTemps(std::string(Config->OutputFile) + ".", /*UseInputModulePath*/ true)); @@ -96,12 +102,12 @@ BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) {} BitcodeCompiler::~BitcodeCompiler() = default; -template <class ELFT> static void undefine(Symbol *S) { - replaceBody<Undefined<ELFT>>(S, S->body()->getName(), /*IsLocal=*/false, - STV_DEFAULT, S->body()->Type, nullptr); +static void undefine(Symbol *S) { + replaceBody<Undefined>(S, S->body()->getName(), /*IsLocal=*/false, + STV_DEFAULT, S->body()->Type, nullptr); } -template <class ELFT> void BitcodeCompiler::add(BitcodeFile &F) { +void BitcodeCompiler::add(BitcodeFile &F) { lto::InputFile &Obj = *F.Obj; unsigned SymNum = 0; std::vector<Symbol *> Syms = F.getSymbols(); @@ -119,14 +125,12 @@ template <class ELFT> void BitcodeCompiler::add(BitcodeFile &F) { // flags an undefined in IR with a definition in ASM as prevailing. // Once IRObjectFile is fixed to report only one symbol this hack can // be removed. - R.Prevailing = - !(ObjSym.getFlags() & object::BasicSymbolRef::SF_Undefined) && - B->File == &F; + R.Prevailing = !ObjSym.isUndefined() && B->File == &F; R.VisibleToRegularObj = Sym->IsUsedInRegularObj || (R.Prevailing && Sym->includeInDynsym()); if (R.Prevailing) - undefine<ELFT>(Sym); + undefine(Sym); } checkError(LTOObj->add(std::move(F.Obj), Resols)); } @@ -137,17 +141,34 @@ std::vector<InputFile *> BitcodeCompiler::compile() { std::vector<InputFile *> Ret; unsigned MaxTasks = LTOObj->getMaxTasks(); Buff.resize(MaxTasks); - - checkError(LTOObj->run([&](size_t Task) { - return llvm::make_unique<lto::NativeObjectStream>( - llvm::make_unique<raw_svector_ostream>(Buff[Task])); - })); + Files.resize(MaxTasks); + + // The --thinlto-cache-dir option specifies the path to a directory in which + // to cache native object files for ThinLTO incremental builds. If a path was + // specified, configure LTO to use it as the cache directory. + lto::NativeObjectCache Cache; + if (!Config->ThinLTOCacheDir.empty()) + Cache = check( + lto::localCache(Config->ThinLTOCacheDir, + [&](size_t Task, std::unique_ptr<MemoryBuffer> MB) { + Files[Task] = std::move(MB); + })); + + checkError(LTOObj->run( + [&](size_t Task) { + return llvm::make_unique<lto::NativeObjectStream>( + llvm::make_unique<raw_svector_ostream>(Buff[Task])); + }, + Cache)); + + if (!Config->ThinLTOCacheDir.empty()) + pruneCache(Config->ThinLTOCacheDir, Config->ThinLTOCachePolicy); for (unsigned I = 0; I != MaxTasks; ++I) { if (Buff[I].empty()) continue; if (Config->SaveTemps) { - if (MaxTasks == 1) + if (I == 0) saveBuffer(Buff[I], Config->OutputFile + ".lto.o"); else saveBuffer(Buff[I], Config->OutputFile + Twine(I) + ".lto.o"); @@ -155,10 +176,10 @@ std::vector<InputFile *> BitcodeCompiler::compile() { InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I], "lto.tmp")); Ret.push_back(Obj); } + + for (std::unique_ptr<MemoryBuffer> &File : Files) + if (File) + Ret.push_back(createObjectFile(*File)); + return Ret; } - -template void BitcodeCompiler::template add<ELF32LE>(BitcodeFile &); -template void BitcodeCompiler::template add<ELF32BE>(BitcodeFile &); -template void BitcodeCompiler::template add<ELF64LE>(BitcodeFile &); -template void BitcodeCompiler::template add<ELF64BE>(BitcodeFile &); |