-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Use the Propeller CFG profile in the PGO analysis map if it is available. #163252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6f84c9a
35b7100
aa37e15
233c44a
c9444c7
9cea27e
58114e7
f5e0711
0ea0690
4d00b06
3fbc277
8c93878
48957ac
0b3716a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ | |
| #include "WinException.h" | ||
| #include "llvm/ADT/APFloat.h" | ||
| #include "llvm/ADT/APInt.h" | ||
| #include "llvm/ADT/BitmaskEnum.h" | ||
| #include "llvm/ADT/DenseMap.h" | ||
| #include "llvm/ADT/STLExtras.h" | ||
| #include "llvm/ADT/SmallPtrSet.h" | ||
|
|
@@ -37,6 +36,7 @@ | |
| #include "llvm/BinaryFormat/COFF.h" | ||
| #include "llvm/BinaryFormat/Dwarf.h" | ||
| #include "llvm/BinaryFormat/ELF.h" | ||
| #include "llvm/CodeGen/BasicBlockSectionsProfileReader.h" | ||
| #include "llvm/CodeGen/GCMetadata.h" | ||
| #include "llvm/CodeGen/GCMetadataPrinter.h" | ||
| #include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h" | ||
|
|
@@ -150,6 +150,7 @@ enum class PGOMapFeaturesEnum { | |
| FuncEntryCount, | ||
| BBFreq, | ||
| BrProb, | ||
| PropellerCFG, | ||
| All, | ||
| }; | ||
| static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures( | ||
|
|
@@ -166,6 +167,12 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures( | |
| "Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is " | ||
| "extracted from PGO related analysis.")); | ||
|
|
||
| static cl::opt<bool> PgoAnalysisMapEmitBBSectionsCfg( | ||
| "pgo-analysis-map-emit-bb-sections-cfg", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we fold this into the existing If we're going to do something more specific than just a |
||
| cl::desc("Enable the post-link cfg information from the basic block " | ||
| "sections profile in the PGO analysis map"), | ||
| cl::Hidden, cl::init(false)); | ||
|
|
||
| static cl::opt<bool> BBAddrMapSkipEmitBBEntries( | ||
| "basic-block-address-map-skip-bb-entries", | ||
| cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP " | ||
|
|
@@ -479,6 +486,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const { | |
| AU.addRequired<MachineBranchProbabilityInfoWrapperPass>(); | ||
| if (EmitBBHash) | ||
| AU.addRequired<MachineBlockHashInfo>(); | ||
| AU.addUsedIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>(); | ||
| } | ||
|
|
||
| bool AsmPrinter::doInitialization(Module &M) { | ||
|
|
@@ -1411,7 +1419,7 @@ static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) { | |
|
|
||
| static llvm::object::BBAddrMap::Features | ||
| getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges, | ||
| bool HasCalls) { | ||
| bool HasCalls, const CfgProfile *FuncCfgProfile) { | ||
| // Ensure that the user has not passed in additional options while also | ||
| // specifying all or none. | ||
| if ((PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None) || | ||
|
|
@@ -1433,17 +1441,17 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges, | |
| bool BrProbEnabled = | ||
| AllFeatures || | ||
| (!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb)); | ||
| bool PostLinkCfgEnabled = FuncCfgProfile && PgoAnalysisMapEmitBBSectionsCfg; | ||
|
|
||
| if ((BBFreqEnabled || BrProbEnabled) && BBAddrMapSkipEmitBBEntries) { | ||
| MF.getFunction().getContext().emitError( | ||
| "BB entries info is required for BBFreq and BrProb " | ||
| "features"); | ||
| "BB entries info is required for BBFreq and BrProb features"); | ||
| } | ||
| return {FuncEntryCountEnabled, BBFreqEnabled, BrProbEnabled, | ||
| MF.hasBBSections() && NumMBBSectionRanges > 1, | ||
| // Use static_cast to avoid breakage of tests on windows. | ||
| static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls, | ||
| static_cast<bool>(EmitBBHash), false}; | ||
| static_cast<bool>(EmitBBHash), PostLinkCfgEnabled}; | ||
| } | ||
|
|
||
| void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { | ||
|
|
@@ -1452,6 +1460,14 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { | |
| assert(BBAddrMapSection && ".llvm_bb_addr_map section is not initialized."); | ||
| bool HasCalls = !CurrentFnCallsiteEndSymbols.empty(); | ||
|
|
||
| const BasicBlockSectionsProfileReader *BBSPR = nullptr; | ||
| if (auto *BBSPRPass = | ||
| getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>()) | ||
| BBSPR = &BBSPRPass->getBBSPR(); | ||
| const CfgProfile *FuncCfgProfile = nullptr; | ||
| if (BBSPR) | ||
| FuncCfgProfile = BBSPR->getFunctionCfgProfile(MF.getFunction().getName()); | ||
|
|
||
| const MCSymbol *FunctionSymbol = getFunctionBegin(); | ||
|
|
||
| OutStreamer->pushSection(); | ||
|
|
@@ -1460,7 +1476,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { | |
| uint8_t BBAddrMapVersion = OutStreamer->getContext().getBBAddrMapVersion(); | ||
| OutStreamer->emitInt8(BBAddrMapVersion); | ||
| OutStreamer->AddComment("feature"); | ||
| auto Features = getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls); | ||
| auto Features = getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls, | ||
| FuncCfgProfile); | ||
| OutStreamer->emitInt8(Features.encode()); | ||
| // Emit BB Information for each basic block in the function. | ||
| if (Features.MultiBBRange) { | ||
|
|
@@ -1565,6 +1582,11 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { | |
| OutStreamer->AddComment("basic block frequency"); | ||
| OutStreamer->emitULEB128IntValue( | ||
| MBFI->getBlockFreq(&MBB).getFrequency()); | ||
| if (Features.PostLinkCfg) { | ||
| OutStreamer->AddComment("basic block frequency (propeller)"); | ||
| OutStreamer->emitULEB128IntValue( | ||
| FuncCfgProfile->getBlockCount(*MBB.getBBID())); | ||
| } | ||
| } | ||
| if (Features.BrProb) { | ||
| unsigned SuccCount = MBB.succ_size(); | ||
|
|
@@ -1576,6 +1598,11 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) { | |
| OutStreamer->AddComment("successor branch probability"); | ||
| OutStreamer->emitULEB128IntValue( | ||
| MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator()); | ||
| if (Features.PostLinkCfg) { | ||
| OutStreamer->AddComment("successor branch frequency (propeller)"); | ||
| OutStreamer->emitULEB128IntValue(FuncCfgProfile->getEdgeCount( | ||
| *MBB.getBBID(), *SuccMBB->getBBID())); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below: Should probably be
CFGProfile, although it doesn't look like anything about capitalization of acronyms is explicitly enumerated in the coding standards.