mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-13 14:35:54 +00:00
IPO, LTO: Plumb the summary from the LTO API into the pass manager.
Differential Revision: https://reviews.llvm.org/D28840 llvm-svn: 292661
This commit is contained in:
parent
fc6ca85023
commit
99444ca866
@ -34,10 +34,11 @@ class Target;
|
||||
|
||||
namespace lto {
|
||||
|
||||
/// Runs a regular LTO backend.
|
||||
/// Runs a regular LTO backend. The regular LTO backend can also act as the
|
||||
/// regular LTO phase of ThinLTO, which may need to access the combined index.
|
||||
Error backend(Config &C, AddStreamFn AddStream,
|
||||
unsigned ParallelCodeGenParallelismLevel,
|
||||
std::unique_ptr<Module> M);
|
||||
std::unique_ptr<Module> M, ModuleSummaryIndex &CombinedIndex);
|
||||
|
||||
/// Runs a ThinLTO backend.
|
||||
Error thinBackend(Config &C, unsigned Task, AddStreamFn AddStream, Module &M,
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
class ModuleSummaryIndex;
|
||||
class Pass;
|
||||
class TargetLibraryInfoImpl;
|
||||
class TargetMachine;
|
||||
@ -123,6 +124,11 @@ public:
|
||||
/// added to the per-module passes.
|
||||
Pass *Inliner;
|
||||
|
||||
/// The module summary index to use for passing information between the
|
||||
/// regular LTO phase and the thin LTO backends, for example the CFI and
|
||||
/// devirtualization type tests.
|
||||
ModuleSummaryIndex *Summary = nullptr;
|
||||
|
||||
bool DisableTailCalls;
|
||||
bool DisableUnitAtATime;
|
||||
bool DisableUnrollLoops;
|
||||
|
@ -601,7 +601,7 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
|
||||
return Error::success();
|
||||
}
|
||||
return backend(Conf, AddStream, RegularLTO.ParallelCodeGenParallelismLevel,
|
||||
std::move(RegularLTO.CombinedModule));
|
||||
std::move(RegularLTO.CombinedModule), ThinLTO.CombinedIndex);
|
||||
}
|
||||
|
||||
/// This class defines the interface to the ThinLTO backend.
|
||||
|
@ -168,13 +168,14 @@ static void runNewPMCustomPasses(Module &Mod, TargetMachine *TM,
|
||||
}
|
||||
|
||||
static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
|
||||
bool IsThinLTO) {
|
||||
bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
|
||||
legacy::PassManager passes;
|
||||
passes.add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
|
||||
|
||||
PassManagerBuilder PMB;
|
||||
PMB.LibraryInfo = new TargetLibraryInfoImpl(Triple(TM->getTargetTriple()));
|
||||
PMB.Inliner = createFunctionInliningPass();
|
||||
PMB.Summary = &CombinedIndex;
|
||||
// Unconditionally verify input since it is not verified before this
|
||||
// point and has unknown origin.
|
||||
PMB.VerifyInput = true;
|
||||
@ -191,10 +192,11 @@ static void runOldPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
|
||||
}
|
||||
|
||||
bool opt(Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
|
||||
bool IsThinLTO) {
|
||||
bool IsThinLTO, ModuleSummaryIndex &CombinedIndex) {
|
||||
if (Conf.OptPipeline.empty())
|
||||
runOldPMPasses(Conf, Mod, TM, IsThinLTO);
|
||||
runOldPMPasses(Conf, Mod, TM, IsThinLTO, CombinedIndex);
|
||||
else
|
||||
// FIXME: Plumb the combined index into the new pass manager.
|
||||
runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
|
||||
Conf.DisableVerify);
|
||||
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
|
||||
@ -291,7 +293,8 @@ static void handleAsmUndefinedRefs(Module &Mod, TargetMachine &TM) {
|
||||
|
||||
Error lto::backend(Config &C, AddStreamFn AddStream,
|
||||
unsigned ParallelCodeGenParallelismLevel,
|
||||
std::unique_ptr<Module> Mod) {
|
||||
std::unique_ptr<Module> Mod,
|
||||
ModuleSummaryIndex &CombinedIndex) {
|
||||
Expected<const Target *> TOrErr = initAndLookupTarget(C, *Mod);
|
||||
if (!TOrErr)
|
||||
return TOrErr.takeError();
|
||||
@ -302,7 +305,7 @@ Error lto::backend(Config &C, AddStreamFn AddStream,
|
||||
handleAsmUndefinedRefs(*Mod, *TM);
|
||||
|
||||
if (!C.CodeGenOnly)
|
||||
if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false))
|
||||
if (!opt(C, TM.get(), 0, *Mod, /*IsThinLTO=*/false, CombinedIndex))
|
||||
return Error::success();
|
||||
|
||||
if (ParallelCodeGenParallelismLevel == 1) {
|
||||
@ -367,7 +370,7 @@ Error lto::thinBackend(Config &Conf, unsigned Task, AddStreamFn AddStream,
|
||||
if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod))
|
||||
return Error::success();
|
||||
|
||||
if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true))
|
||||
if (!opt(Conf, TM.get(), Task, Mod, /*IsThinLTO=*/true, CombinedIndex))
|
||||
return Error::success();
|
||||
|
||||
codegen(Conf, TM.get(), AddStream, Task, Mod);
|
||||
|
@ -833,6 +833,10 @@ void PassManagerBuilder::populateThinLTOPassManager(
|
||||
if (VerifyInput)
|
||||
PM.add(createVerifierPass());
|
||||
|
||||
if (Summary)
|
||||
PM.add(
|
||||
createLowerTypeTestsPass(LowerTypeTestsSummaryAction::Import, Summary));
|
||||
|
||||
populateModulePassManager(PM);
|
||||
|
||||
if (VerifyOutput)
|
||||
@ -857,8 +861,9 @@ void PassManagerBuilder::populateLTOPassManager(legacy::PassManagerBase &PM) {
|
||||
// Lower type metadata and the type.test intrinsic. This pass supports Clang's
|
||||
// control flow integrity mechanisms (-fsanitize=cfi*) and needs to run at
|
||||
// link time if CFI is enabled. The pass does nothing if CFI is disabled.
|
||||
PM.add(createLowerTypeTestsPass(LowerTypeTestsSummaryAction::None,
|
||||
/*Summary=*/nullptr));
|
||||
PM.add(createLowerTypeTestsPass(Summary ? LowerTypeTestsSummaryAction::Export
|
||||
: LowerTypeTestsSummaryAction::None,
|
||||
Summary));
|
||||
|
||||
if (OptLevel != 0)
|
||||
addLateLTOOptimizationPasses(PM);
|
||||
|
21
test/LTO/Resolution/X86/lowertypetests.ll
Normal file
21
test/LTO/Resolution/X86/lowertypetests.ll
Normal file
@ -0,0 +1,21 @@
|
||||
; RUN: opt -thinlto-bc -o %t %s
|
||||
; RUN: llvm-lto2 -r %t,f,plx -r %t,foo,lx -r %t,foo,plx -o %t1 %t
|
||||
; RUN: llvm-nm %t1.0 | FileCheck --check-prefix=MERGED %s
|
||||
; RUN: llvm-nm %t1.1 | FileCheck %s
|
||||
|
||||
; MERGED: R __typeid_foo_global_addr
|
||||
; CHECK: U __typeid_foo_global_addr
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
@foo = global i32 0, !type !0
|
||||
|
||||
define i1 @f(i8* %ptr) {
|
||||
%p = call i1 @llvm.type.test(i8* %ptr, metadata !"foo")
|
||||
ret i1 %p
|
||||
}
|
||||
|
||||
declare i1 @llvm.type.test(i8* %ptr, metadata %typeid) nounwind readnone
|
||||
|
||||
!0 = !{i32 0, !"foo"}
|
Loading…
Reference in New Issue
Block a user