From d00c9cd31eee78af5f7ff85be5b55edf4234ffd2 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 22 Aug 2016 06:25:41 +0000 Subject: [PATCH] [LTO] Add a "CodeGenOnly" option. Allows the client to skip the optimizer. Summary: Slowly getting on par with libLTO Reviewers: tejohnson Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D23615 llvm-svn: 279416 --- include/llvm/LTO/Config.h | 3 +++ lib/LTO/LTO.cpp | 40 ++++++++++++++++++++------------------- lib/LTO/LTOBackend.cpp | 10 ++++++++-- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/include/llvm/LTO/Config.h b/include/llvm/LTO/Config.h index 315af33a91a..e3d1fb2d860 100644 --- a/include/llvm/LTO/Config.h +++ b/include/llvm/LTO/Config.h @@ -52,6 +52,9 @@ struct Config { unsigned OptLevel = 2; bool DisableVerify = false; + /// Disable entirely the optimizer, including importing for ThinLTO + bool CodeGenOnly = false; + /// Setting this field will replace target triples in input files with this /// triple. std::string OverrideTriple; diff --git a/lib/LTO/LTO.cpp b/lib/LTO/LTO.cpp index bd11085ed1c..8ceb5a2c1c8 100644 --- a/lib/LTO/LTO.cpp +++ b/lib/LTO/LTO.cpp @@ -365,27 +365,29 @@ Error LTO::runRegularLTO(AddOutputFn AddOutput) { !Conf.PreOptModuleHook(0, *RegularLTO.CombinedModule)) return Error(); - for (const auto &R : GlobalResolutions) { - if (R.second.IRName.empty()) - continue; - if (R.second.Partition != 0 && - R.second.Partition != GlobalResolution::External) - continue; + if (!Conf.CodeGenOnly) { + for (const auto &R : GlobalResolutions) { + if (R.second.IRName.empty()) + continue; + if (R.second.Partition != 0 && + R.second.Partition != GlobalResolution::External) + continue; - GlobalValue *GV = RegularLTO.CombinedModule->getNamedValue(R.second.IRName); - // Ignore symbols defined in other partitions. - if (!GV || GV->hasLocalLinkage()) - continue; - GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global - : GlobalValue::UnnamedAddr::None); - if (R.second.Partition == 0) - GV->setLinkage(GlobalValue::InternalLinkage); + GlobalValue *GV = + RegularLTO.CombinedModule->getNamedValue(R.second.IRName); + // Ignore symbols defined in other partitions. + if (!GV || GV->hasLocalLinkage()) + continue; + GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global + : GlobalValue::UnnamedAddr::None); + if (R.second.Partition == 0) + GV->setLinkage(GlobalValue::InternalLinkage); + } + + if (Conf.PostInternalizeModuleHook && + !Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule)) + return Error(); } - - if (Conf.PostInternalizeModuleHook && - !Conf.PostInternalizeModuleHook(0, *RegularLTO.CombinedModule)) - return Error(); - return backend(Conf, AddOutput, RegularLTO.ParallelCodeGenParallelismLevel, std::move(RegularLTO.CombinedModule)); } diff --git a/lib/LTO/LTOBackend.cpp b/lib/LTO/LTOBackend.cpp index 935152b970d..a89364e46a0 100644 --- a/lib/LTO/LTOBackend.cpp +++ b/lib/LTO/LTOBackend.cpp @@ -224,8 +224,9 @@ Error lto::backend(Config &C, AddOutputFn AddOutput, std::unique_ptr TM = createTargetMachine(C, M->getTargetTriple(), *TOrErr); - if (!opt(C, TM.get(), 0, *M, /*IsThinLto=*/false)) - return Error(); + if (!C.CodeGenOnly) + if (!opt(C, TM.get(), 0, *M, /*IsThinLto=*/false)) + return Error(); if (ParallelCodeGenParallelismLevel == 1) codegen(C, TM.get(), AddOutput, 0, *M); @@ -247,6 +248,11 @@ Error lto::thinBackend(Config &Conf, unsigned Task, AddOutputFn AddOutput, std::unique_ptr TM = createTargetMachine(Conf, Mod.getTargetTriple(), *TOrErr); + if (Conf.CodeGenOnly) { + codegen(Conf, TM.get(), AddOutput, Task, Mod); + return Error(); + } + if (Conf.PreOptModuleHook && !Conf.PreOptModuleHook(Task, Mod)) return Error();