diff options
author | Vitaly Buka <vitalybuka@google.com> | 2020-06-02 01:19:57 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2020-06-10 21:02:54 -0700 |
commit | 5b1c70a48d97513563ced9f39c631f302c071c75 (patch) | |
tree | 14cec44a512b3a5381a04368f6a808303732e88b /llvm/lib/LTO/LTOBackend.cpp | |
parent | 4880853fb65c0270afc50467ebaaa9dafd25fa9d (diff) | |
download | llvm-5b1c70a48d97513563ced9f39c631f302c071c75.zip llvm-5b1c70a48d97513563ced9f39c631f302c071c75.tar.gz llvm-5b1c70a48d97513563ced9f39c631f302c071c75.tar.bz2 |
[StackSafety] Pass summary into codegen
Summary:
The patch wraps ThinLTO index into immutable
pass which can be used by StackSafety analysis.
Reviewers: eugenis, pcc
Reviewed By: eugenis
Subscribers: hiraditya, steven_wu, dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D80985
Diffstat (limited to 'llvm/lib/LTO/LTOBackend.cpp')
-rw-r--r-- | llvm/lib/LTO/LTOBackend.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index 79c5281..0c395f9 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -16,6 +16,7 @@ #include "llvm/LTO/LTOBackend.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CGSCCPassManager.h" +#include "llvm/Analysis/ModuleSummaryAnalysis.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Bitcode/BitcodeReader.h" @@ -363,7 +364,8 @@ static void EmitBitcodeSection(Module &M, const Config &Conf) { } void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, - unsigned Task, Module &Mod) { + unsigned Task, Module &Mod, + const ModuleSummaryIndex &CombinedIndex) { if (Conf.PreCodeGenModuleHook && !Conf.PreCodeGenModuleHook(Task, Mod)) return; @@ -392,6 +394,8 @@ void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, auto Stream = AddStream(Task); legacy::PassManager CodeGenPasses; + CodeGenPasses.add( + createImmutableModuleSummaryIndexWrapperPass(&CombinedIndex)); if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, DwoOut ? &DwoOut->os() : nullptr, Conf.CGFileType)) @@ -404,7 +408,8 @@ void codegen(const Config &Conf, TargetMachine *TM, AddStreamFn AddStream, void splitCodeGen(const Config &C, TargetMachine *TM, AddStreamFn AddStream, unsigned ParallelCodeGenParallelismLevel, - std::unique_ptr<Module> Mod) { + std::unique_ptr<Module> Mod, + const ModuleSummaryIndex &CombinedIndex) { ThreadPool CodegenThreadPool( heavyweight_hardware_concurrency(ParallelCodeGenParallelismLevel)); unsigned ThreadCount = 0; @@ -437,7 +442,8 @@ void splitCodeGen(const Config &C, TargetMachine *TM, AddStreamFn AddStream, std::unique_ptr<TargetMachine> TM = createTargetMachine(C, T, *MPartInCtx); - codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx); + codegen(C, TM.get(), AddStream, ThreadId, *MPartInCtx, + CombinedIndex); }, // Pass BC using std::move to ensure that it get moved rather than // copied into the thread's context. @@ -493,10 +499,10 @@ Error lto::backend(const Config &C, AddStreamFn AddStream, } if (ParallelCodeGenParallelismLevel == 1) { - codegen(C, TM.get(), AddStream, 0, *Mod); + codegen(C, TM.get(), AddStream, 0, *Mod, CombinedIndex); } else { splitCodeGen(C, TM.get(), AddStream, ParallelCodeGenParallelismLevel, - std::move(Mod)); + std::move(Mod), CombinedIndex); } return Error::success(); } @@ -546,7 +552,7 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream, Mod.setPartialSampleProfileRatio(CombinedIndex); if (Conf.CodeGenOnly) { - codegen(Conf, TM.get(), AddStream, Task, Mod); + codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex); return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile)); } @@ -597,6 +603,6 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream, /*ExportSummary=*/nullptr, /*ImportSummary=*/&CombinedIndex)) return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile)); - codegen(Conf, TM.get(), AddStream, Task, Mod); + codegen(Conf, TM.get(), AddStream, Task, Mod, CombinedIndex); return finalizeOptimizationRemarks(std::move(DiagnosticOutputFile)); } |