[PATCH] D18235: [LTO] Call the optimizer before invoking codegen
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 16 18:08:55 PDT 2016
davide created this revision.
davide added a reviewer: rafael.
davide added subscribers: llvm-commits, joker.eph, silvas.
This is the required plumbing needed to run the LTO passes.
Now the global constructor is (correctly) stripped away from the produced shared library.
http://reviews.llvm.org/D18235
Files:
ELF/SymbolTable.cpp
test/ELF/lto/ctors.ll
Index: test/ELF/lto/ctors.ll
===================================================================
--- test/ELF/lto/ctors.ll
+++ test/ELF/lto/ctors.ll
@@ -11,5 +11,5 @@
ret void
}
-; The llvm.global_ctors should end up producing constructors.
-; CHECK: Name: .ctors
+; The llvm.global_ctors should be stripped away.
+; CHECK-NOT: Name: .ctors
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -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,16 @@
OS << Buffer;
}
+// This is for use when debugging LTO.
+static void saveBCFile(Module &M, bool Optimized) {
+ std::error_code EC;
+ raw_fd_ostream OS(Config->OutputFile.str() +
+ (Optimized ? ".lto.opt.bc" : ".lto.bc"), 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 +140,24 @@
std::unique_ptr<TargetMachine> TM(
TheTarget->createTargetMachine(TripleStr, "", "", Options, R));
+ // LTOPasses.
+ M.setDataLayout(TM->createDataLayout());
+ 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);
+
+ if (Config->SaveTemps)
+ saveBCFile(M, true /* Optimized */);
+
raw_svector_ostream OS(OwningLTOData);
legacy::PassManager CodeGenPasses;
if (TM->addPassesToEmitFile(CodeGenPasses, OS,
@@ -169,15 +201,6 @@
[](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 @@
for (const std::unique_ptr<BitcodeFile> &F : BitcodeFiles)
addBitcodeFile(Mover, *F, Context);
if (Config->SaveTemps)
- saveBCFile(Combined);
+ saveBCFile(Combined, false /* Optimized */);
std::unique_ptr<InputFile> F = codegen(Combined);
ObjectFiles.emplace_back(cast<ObjectFile<ELFT>>(F.release()));
return &*ObjectFiles.back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18235.50900.patch
Type: text/x-patch
Size: 3401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160317/d7e894ef/attachment.bin>
More information about the llvm-commits
mailing list