diff options
author | Rong Xu <xur@google.com> | 2021-08-18 16:59:02 -0700 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2021-08-18 18:37:35 -0700 |
commit | 5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4 (patch) | |
tree | d4d0b1f29de6c82b70765774da2542c3f37c76e4 /llvm/lib/CodeGen/TargetPassConfig.cpp | |
parent | c777e51468f5d44ad4600344683ecf9b46aa2b0f (diff) | |
download | llvm-5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4.zip llvm-5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4.tar.gz llvm-5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4.tar.bz2 |
[SampleFDO] Flow Sensitive Sample FDO (FSAFDO) profile loader
This patch implements Flow Sensitive Sample FDO (FSAFDO) profile
loader. We have two profile loaders for FS profile,
one before RegAlloc and one before BlockPlacement.
To enable it, when -fprofile-sample-use=<profile> is specified,
add "-enable-fs-discriminator=true \
-disable-ra-fsprofile-loader=false \
-disable-layout-fsprofile-loader=false"
to turn on the FS profile loaders.
Differential Revision: https://reviews.llvm.org/D107878
Diffstat (limited to 'llvm/lib/CodeGen/TargetPassConfig.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetPassConfig.cpp | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp index c31dece..2a90c31 100644 --- a/llvm/lib/CodeGen/TargetPassConfig.cpp +++ b/llvm/lib/CodeGen/TargetPassConfig.cpp @@ -172,6 +172,24 @@ static cl::opt<bool> FSNoFinalDiscrim("fs-no-final-discrim", cl::init(false), cl::Hidden, cl::desc("Do not insert FS-AFDO discriminators before " "emit.")); +// Disable MIRProfileLoader before RegAlloc. This is for for debugging and +// tuning purpose. +static cl::opt<bool> DisableRAFSProfileLoader( + "disable-ra-fsprofile-loader", cl::init(true), cl::Hidden, + cl::desc("Disable MIRProfileLoader before RegAlloc")); +// Disable MIRProfileLoader before BloackPlacement. This is for for debugging +// and tuning purpose. +static cl::opt<bool> DisableLayoutFSProfileLoader( + "disable-layout-fsprofile-loader", cl::init(true), cl::Hidden, + cl::desc("Disable MIRProfileLoader before BlockPlacement")); +// Specify FSProfile file name. +static cl::opt<std::string> + FSProfileFile("fs-profile-file", cl::init(""), cl::value_desc("filename"), + cl::desc("Flow Sensitive profile file name."), cl::Hidden); +// Specify Remapping file for FSProfile. +static cl::opt<std::string> FSRemappingFile( + "fs-remapping-file", cl::init(""), cl::value_desc("filename"), + cl::desc("Flow Sensitive profile remapping file name."), cl::Hidden); // Temporary option to allow experimenting with MachineScheduler as a post-RA // scheduler. Targets can "properly" enable this with @@ -308,6 +326,28 @@ static IdentifyingPassPtr overridePass(AnalysisID StandardID, return TargetID; } +// Find the FSProfile file name. The internal option takes the precedence +// before getting from TargetMachine. +static const std::string getFSProfileFile(const TargetMachine *TM) { + if (!FSProfileFile.empty()) + return FSProfileFile.getValue(); + const Optional<PGOOptions> &PGOOpt = TM->getPGOOption(); + if (PGOOpt == None || PGOOpt->Action != PGOOptions::SampleUse) + return std::string(); + return PGOOpt->ProfileFile; +} + +// Find the Profile remapping file name. The internal option takes the +// precedence before getting from TargetMachine. +static const std::string getFSRemappingFile(const TargetMachine *TM) { + if (!FSRemappingFile.empty()) + return FSRemappingFile.getValue(); + const Optional<PGOOptions> &PGOOpt = TM->getPGOOption(); + if (PGOOpt == None || PGOOpt->Action != PGOOptions::SampleUse) + return std::string(); + return PGOOpt->ProfileRemappingFile; +} + //===---------------------------------------------------------------------===// /// TargetPassConfig //===---------------------------------------------------------------------===// @@ -1115,9 +1155,15 @@ void TargetPassConfig::addMachinePasses() { // Add a FSDiscriminator pass right before RA, so that we could get // more precise SampleFDO profile for RA. - if (EnableFSDiscriminator) + if (EnableFSDiscriminator) { addPass(createMIRAddFSDiscriminatorsPass( sampleprof::FSDiscriminatorPass::Pass1)); + const std::string ProfileFile = getFSProfileFile(TM); + if (!ProfileFile.empty() && !DisableRAFSProfileLoader) + addPass( + createMIRProfileLoaderPass(ProfileFile, getFSRemappingFile(TM), + sampleprof::FSDiscriminatorPass::Pass1)); + } // Run register allocation and passes that are tightly coupled with it, // including phi elimination and scheduling. @@ -1471,9 +1517,15 @@ bool TargetPassConfig::addGCPasses() { /// Add standard basic block placement passes. void TargetPassConfig::addBlockPlacement() { - if (EnableFSDiscriminator) + if (EnableFSDiscriminator) { addPass(createMIRAddFSDiscriminatorsPass( sampleprof::FSDiscriminatorPass::Pass2)); + const std::string ProfileFile = getFSProfileFile(TM); + if (!ProfileFile.empty() && !DisableLayoutFSProfileLoader) + addPass( + createMIRProfileLoaderPass(ProfileFile, getFSRemappingFile(TM), + sampleprof::FSDiscriminatorPass::Pass2)); + } if (addPass(&MachineBlockPlacementID)) { // Run a separate pass to collect block placement statistics. if (EnableBlockPlacementStats) |