-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[CodeGen][NPM] Update BranchFolderLegacy make tail merge configurable via flag #135277
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 11 commits
1439764
1129f40
7d8d9df
9b95974
17fcc45
73b228a
f2dd02c
fc156b5
b49d6d3
1293477
756e1a5
501a1cf
61251d3
ec4571a
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 |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ | |
| #include "llvm/CodeGen/MachineSizeOpts.h" | ||
| #include "llvm/CodeGen/TargetInstrInfo.h" | ||
| #include "llvm/CodeGen/TargetOpcodes.h" | ||
| #include "llvm/CodeGen/TargetPassConfig.h" | ||
| #include "llvm/CodeGen/TargetRegisterInfo.h" | ||
| #include "llvm/CodeGen/TargetSubtargetInfo.h" | ||
| #include "llvm/IR/DebugInfoMetadata.h" | ||
|
|
@@ -90,18 +89,20 @@ namespace { | |
|
|
||
| /// BranchFolderPass - Wrap branch folder in a machine function pass. | ||
| class BranchFolderLegacy : public MachineFunctionPass { | ||
| bool EnableTailMerge; | ||
|
|
||
| public: | ||
| static char ID; | ||
|
|
||
| explicit BranchFolderLegacy() : MachineFunctionPass(ID) {} | ||
| explicit BranchFolderLegacy(bool EnableTailMerge = true) | ||
| : MachineFunctionPass(ID), EnableTailMerge(EnableTailMerge) {} | ||
|
|
||
| bool runOnMachineFunction(MachineFunction &MF) override; | ||
|
|
||
| void getAnalysisUsage(AnalysisUsage &AU) const override { | ||
| AU.addRequired<MachineBlockFrequencyInfoWrapperPass>(); | ||
| AU.addRequired<MachineBranchProbabilityInfoWrapperPass>(); | ||
| AU.addRequired<ProfileSummaryInfoWrapperPass>(); | ||
| AU.addRequired<TargetPassConfig>(); | ||
| MachineFunctionPass::getAnalysisUsage(AU); | ||
| } | ||
|
|
||
|
|
@@ -123,9 +124,6 @@ INITIALIZE_PASS(BranchFolderLegacy, DEBUG_TYPE, "Control Flow Optimizer", false, | |
| PreservedAnalyses BranchFolderPass::run(MachineFunction &MF, | ||
| MachineFunctionAnalysisManager &MFAM) { | ||
| MFPropsModifier _(*this, MF); | ||
| bool EnableTailMerge = | ||
|
Collaborator
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. Since you're removing it here, the NPM require the flag https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Passes/CodeGenPassBuilder.h#L1235 |
||
| !MF.getTarget().requiresStructuredCFG() && this->EnableTailMerge; | ||
|
|
||
| auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF); | ||
| auto *PSI = MFAM.getResult<ModuleAnalysisManagerMachineFunctionProxy>(MF) | ||
| .getCachedResult<ProfileSummaryAnalysis>( | ||
|
|
@@ -144,15 +142,21 @@ PreservedAnalyses BranchFolderPass::run(MachineFunction &MF, | |
| return getMachineFunctionPassPreservedAnalyses(); | ||
| } | ||
|
|
||
| void BranchFolderPass::printPipeline( | ||
| raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) { | ||
| OS << MapClassName2PassName(name()); | ||
| if (EnableTailMerge) | ||
| OS << "<enable-tail-merge>"; | ||
| } | ||
|
|
||
| bool BranchFolderLegacy::runOnMachineFunction(MachineFunction &MF) { | ||
| if (skipFunction(MF.getFunction())) | ||
| return false; | ||
|
|
||
| TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>(); | ||
| // TailMerge can create jump into if branches that make CFG irreducible for | ||
| // HW that requires structurized CFG. | ||
| bool EnableTailMerge = !MF.getTarget().requiresStructuredCFG() && | ||
| PassConfig->getEnableTailMerge(); | ||
| bool EnableTailMerge = | ||
mikhailramalho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| !MF.getTarget().requiresStructuredCFG() && this->EnableTailMerge; | ||
mikhailramalho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MBFIWrapper MBBFreqInfo( | ||
| getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI()); | ||
| BranchFolder Folder( | ||
|
|
@@ -2080,3 +2084,7 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) { | |
| ++NumHoist; | ||
| return true; | ||
| } | ||
|
|
||
| MachineFunctionPass *llvm::createBranchFolderPass(bool EnableTailMerge = true) { | ||
| return new BranchFolderLegacy(EnableTailMerge); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -707,6 +707,10 @@ void TargetPassConfig::addPass(Pass *P) { | |
| // and shouldn't reference it. | ||
| AnalysisID PassID = P->getPassID(); | ||
|
|
||
| IdentifyingPassPtr TargetID = getPassSubstitution(PassID); | ||
| if (!overridePass(PassID, TargetID).isValid()) | ||
| return; | ||
|
||
|
|
||
| if (StartBefore == PassID && StartBeforeCount++ == StartBeforeInstanceNum) | ||
| Started = true; | ||
| if (StopBefore == PassID && StopBeforeCount++ == StopBeforeInstanceNum) | ||
|
|
@@ -1514,7 +1518,8 @@ void TargetPassConfig::addMachineLateOptimization() { | |
| addPass(&MachineLateInstrsCleanupID); | ||
|
|
||
| // Branch folding must be run after regalloc and prolog/epilog insertion. | ||
| addPass(&BranchFolderPassID); | ||
| addPass(createBranchFolderPass(!TM->requiresStructuredCFG() && | ||
| getEnableTailMerge())); | ||
|
|
||
| // Tail duplication. | ||
| // Note that duplicating tail just increases code size and degrades | ||
|
|
||
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.
Are you talking about the default argument? I see that
BranchFolderPassalready takes abool EnableTailMerge:llvm-project/llvm/include/llvm/CodeGen/BranchFoldingPass.h
Line 19 in b39ab7a