[PATCH] D34720: Hook the sample PGO machinery in the new PM
Dehao Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 15:50:13 PDT 2017
danielcdh created this revision.
Herald added a subscriber: sanjoy.
This patch hooks up SampleProfileLoaderPass with the new PM.
https://reviews.llvm.org/D34720
Files:
include/llvm/Passes/PassBuilder.h
include/llvm/Transforms/SampleProfile.h
lib/Passes/PassBuilder.cpp
lib/Transforms/IPO/SampleProfile.cpp
Index: lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- lib/Transforms/IPO/SampleProfile.cpp
+++ lib/Transforms/IPO/SampleProfile.cpp
@@ -1484,7 +1484,8 @@
PreservedAnalyses SampleProfileLoaderPass::run(Module &M,
ModuleAnalysisManager &AM) {
- SampleProfileLoader SampleLoader(SampleProfileFile);
+ SampleProfileLoader SampleLoader(
+ ProfileFileName.empty() ? SampleProfileFile : ProfileFileName);
SampleLoader.doInitialization(M);
Index: lib/Passes/PassBuilder.cpp
===================================================================
--- lib/Passes/PassBuilder.cpp
+++ lib/Passes/PassBuilder.cpp
@@ -527,13 +527,17 @@
// Add all the requested passes for PGO, if requested.
if (PGOOpt) {
- assert(PGOOpt->RunProfileGen || PGOOpt->SamplePGO ||
+ assert(PGOOpt->RunProfileGen || !PGOOpt->SampleProfileFile.empty() ||
!PGOOpt->ProfileUseFile.empty());
- addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
- PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+ if (PGOOpt->SampleProfileFile.empty())
+ addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
+ PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+ else
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
// Indirect call promotion that promotes intra-module targes only.
- MPM.addPass(PGOIndirectCallPromotion(false, PGOOpt && PGOOpt->SamplePGO));
+ MPM.addPass(PGOIndirectCallPromotion(
+ false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
}
// Require the GlobalsAA analysis for the module so we can query it within
@@ -772,9 +776,9 @@
// During the ThinLTO backend phase we perform early indirect call promotion
// here, before globalopt. Otherwise imported available_externally functions
// look unreferenced and are removed.
- MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
- PGOOpt && PGOOpt->SamplePGO &&
- !PGOOpt->ProfileUseFile.empty()));
+ MPM.addPass(PGOIndirectCallPromotion(
+ true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
+ !PGOOpt->ProfileUseFile.empty()));
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
@@ -814,8 +818,8 @@
// left by the earlier promotion pass that promotes intra-module targets.
// This two-step promotion is to save the compile time. For LTO, it should
// produce the same result as if we only do promotion here.
- MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
- PGOOpt && PGOOpt->SamplePGO));
+ MPM.addPass(PGOIndirectCallPromotion(
+ true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
// Propagate constants at call sites into the functions they call. This
// opens opportunities for globalopt (and inlining) by substituting function
Index: include/llvm/Transforms/SampleProfile.h
===================================================================
--- include/llvm/Transforms/SampleProfile.h
+++ include/llvm/Transforms/SampleProfile.h
@@ -21,6 +21,10 @@
class SampleProfileLoaderPass : public PassInfoMixin<SampleProfileLoaderPass> {
public:
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+ SampleProfileLoaderPass(std::string File = "") : ProfileFileName(File) {}
+
+private:
+ std::string ProfileFileName;
};
} // End llvm namespace
Index: include/llvm/Passes/PassBuilder.h
===================================================================
--- include/llvm/Passes/PassBuilder.h
+++ include/llvm/Passes/PassBuilder.h
@@ -31,8 +31,8 @@
struct PGOOptions {
std::string ProfileGenFile = "";
std::string ProfileUseFile = "";
+ std::string SampleProfileFile = "";
bool RunProfileGen = false;
- bool SamplePGO = false;
};
/// \brief This class provides access to building LLVM's passes.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34720.104295.patch
Type: text/x-patch
Size: 4140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170627/d213ff74/attachment.bin>
More information about the llvm-commits
mailing list