[lld] r263761 - [LTO] Call the optimizer before invoking codegen.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 18 02:55:16 PDT 2016
On Fri, Mar 18, 2016 at 12:35 AM, Davide Italiano via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: davide
> Date: Thu Mar 17 18:35:34 2016
> New Revision: 263761
>
> URL: http://llvm.org/viewvc/llvm-project?rev=263761&view=rev
> Log:
> [LTO] Call the optimizer before invoking codegen.
>
> This is the required plumbing needed to run the LTO passes.
>
> Differential Revision: http://reviews.llvm.org/D18235
>
> Modified:
> lld/trunk/ELF/SymbolTable.cpp
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=263761&r1=263760&r2=263761&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Thu Mar 17 18:35:34 2016
> @@ -18,12 +18,16 @@
> #include "Config.h"
> #include "Error.h"
> #include "Symbols.h"
> +#include "llvm/Analysis/TargetLibraryInfo.h"
> +#include "llvm/Analysis/TargetTransformInfo.h"
> #include "llvm/Bitcode/ReaderWriter.h"
> #include "llvm/IR/LegacyPassManager.h"
> #include "llvm/Linker/IRMover.h"
> #include "llvm/Support/StringSaver.h"
> #include "llvm/Support/TargetRegistry.h"
> #include "llvm/Target/TargetMachine.h"
> +#include "llvm/Transforms/IPO.h"
> +#include "llvm/Transforms/IPO/PassManagerBuilder.h"
>
> using namespace llvm;
> using namespace llvm::object;
> @@ -106,6 +110,15 @@ static void saveLtoObjectFile(StringRef
> OS << Buffer;
> }
>
> +// This is for use when debugging LTO.
> +static void saveBCFile(Module &M, StringRef Suffix) {
> + std::error_code EC;
> + raw_fd_ostream OS(Config->OutputFile.str() + Suffix.str(), EC,
> + sys::fs::OpenFlags::F_None);
> + check(EC);
> + WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
> +}
> +
> // Codegen the module M and returns the resulting InputFile.
> template <class ELFT>
> std::unique_ptr<InputFile> SymbolTable<ELFT>::codegen(Module &M) {
> @@ -126,6 +139,25 @@ std::unique_ptr<InputFile> SymbolTable<E
> std::unique_ptr<TargetMachine> TM(
> TheTarget->createTargetMachine(TripleStr, "", "", Options, R));
>
> + // Run LTO passes.
> + // FIXME: Reduce code duplication by sharing this code with the gold
> plugin.
> + legacy::PassManager LtoPasses;
> + LtoPasses.add(
> + createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
> + PassManagerBuilder PMB;
> + PMB.LibraryInfo = new
> TargetLibraryInfoImpl(Triple(TM->getTargetTriple()));
> + PMB.Inliner = createFunctionInliningPass();
> + PMB.VerifyInput = true;
> + PMB.VerifyOutput = true;
> + PMB.LoopVectorize = true;
> + PMB.SLPVectorize = true;
> + PMB.OptLevel = 2; // FIXME: This should be an option.
> + PMB.populateLTOPassManager(LtoPasses);
> + LtoPasses.run(M);
>
This function is getting longer. Can you make this new code a separate
function?
+
> + if (Config->SaveTemps)
> + saveBCFile(M, ".lto.opt.bc");
> +
> raw_svector_ostream OS(OwningLTOData);
> legacy::PassManager CodeGenPasses;
> if (TM->addPassesToEmitFile(CodeGenPasses, OS,
> @@ -169,15 +201,6 @@ static void addBitcodeFile(IRMover &Move
> [](GlobalValue &, IRMover::ValueAdder) {});
> }
>
> -// This is for use when debugging LTO.
> -static void saveBCFile(Module &M) {
> - std::error_code EC;
> - raw_fd_ostream OS(Config->OutputFile.str() + ".lto.bc", EC,
> - sys::fs::OpenFlags::F_None);
> - check(EC);
> - WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
> -}
> -
> // Merge all the bitcode files we have seen, codegen the result and return
> // the resulting ObjectFile.
> template <class ELFT>
> @@ -188,7 +211,7 @@ elf::ObjectFile<ELFT> *SymbolTable<ELFT>
> for (const std::unique_ptr<BitcodeFile> &F : BitcodeFiles)
> addBitcodeFile(Mover, *F, Context);
> if (Config->SaveTemps)
> - saveBCFile(Combined);
> + saveBCFile(Combined, ".lto.bc");
> std::unique_ptr<InputFile> F = codegen(Combined);
> ObjectFiles.emplace_back(cast<ObjectFile<ELFT>>(F.release()));
> return &*ObjectFiles.back();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160318/e416b442/attachment.html>
More information about the llvm-commits
mailing list