Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/BranchFoldingPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class BranchFolderPass : public PassInfoMixin<BranchFolderPass> {
return MachineFunctionProperties().set(
MachineFunctionProperties::Property::NoPHIs);
}

void printPipeline(raw_ostream &OS,
function_ref<StringRef(StringRef)> MapClassName2PassName);
};

} // namespace llvm
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ namespace llvm {
/// branches.
extern char &BranchFolderPassID;

MachineFunctionPass *createBranchFolderPass(bool EnableTailMerge);

/// BranchRelaxation - This pass replaces branches that need to jump further
/// than is supported by a branch instruction.
extern char &BranchRelaxationPassID;
Expand Down
23 changes: 17 additions & 6 deletions llvm/lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That added the initial port to the new pm. This is now changing the pass arguments in the old PM, without the matching new PM change

Are you talking about the default argument? I see that BranchFolderPass already takes a bool EnableTailMerge:

BranchFolderPass(bool EnableTailMerge) : 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);
}

Expand Down Expand Up @@ -144,15 +145,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 =
!MF.getTarget().requiresStructuredCFG() && this->EnableTailMerge;
MBFIWrapper MBBFreqInfo(
getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI());
BranchFolder Folder(
Expand Down Expand Up @@ -2080,3 +2087,7 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
++NumHoist;
return true;
}

MachineFunctionPass *llvm::createBranchFolderPass(bool EnableTailMerge = true) {
return new BranchFolderLegacy(EnableTailMerge);
}
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/TargetPassConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need to touch the override infrastructure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't get it... What do you mean?

I had to add this to check if the pass was disabled. It's a copy-and-paste from the addPass(AnalysisID PassID) method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the problem. You shouldn't have to do anything like this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced this check with a isPassSubstitutedOrOverridden check, similar to how it's done for createPrologEpilogInserterPass. Does this address your comment?


if (StartBefore == PassID && StartBeforeCount++ == StartBeforeInstanceNum)
Started = true;
if (StopBefore == PassID && StopBeforeCount++ == StopBeforeInstanceNum)
Expand Down Expand Up @@ -1514,7 +1518,7 @@ void TargetPassConfig::addMachineLateOptimization() {
addPass(&MachineLateInstrsCleanupID);

// Branch folding must be run after regalloc and prolog/epilog insertion.
addPass(&BranchFolderPassID);
addPass(createBranchFolderPass(getEnableTailMerge()));

// Tail duplication.
// Note that duplicating tail just increases code size and degrades
Expand Down
Loading