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