Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
19 changes: 17 additions & 2 deletions llvm/lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ 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;

Expand Down Expand Up @@ -144,6 +147,13 @@ 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;
Expand All @@ -152,7 +162,8 @@ bool BranchFolderLegacy::runOnMachineFunction(MachineFunction &MF) {
// TailMerge can create jump into if branches that make CFG irreducible for
// HW that requires structurized CFG.
bool EnableTailMerge = !MF.getTarget().requiresStructuredCFG() &&
PassConfig->getEnableTailMerge();
PassConfig->getEnableTailMerge() &&
Copy link
Member Author

Choose a reason for hiding this comment

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

This global state should be moved to only change the pass parameter

Do you mean I should remove the PassConfig->getEnableTailMerge()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it can be passed as the EnableTailMerge parameter when TargetPassConfig creates this pass instance (where currently this is done through its ID).

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, so I did 9b95974, but I'm getting a weird error: when the branch folding pass runs now, I get that the pre-conditions are not valid:

MachineFunctionProperties required by Control Flow Optimizer pass are not met by function RWBufferStore_Vec4_I32.
Required properties: NoPHIs
Current properties: IsSSA, TracksLiveness, Legalized, Selected

This seems to only happen because of this change:

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

The calling addPass with the BranchFolderPassID, it doesn't seem to be added to the list of passes because char BranchFolderLegacy::ID = 0, whereas when we call createBranchFolderPass, the pass is added and fails.

Maybe I'm missing some detail here, but the pass doesn't seem to run at all before my changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the failing tests, the branch folding pass is disabled here:

disablePass(&BranchFolderPassID);

So by calling createBranchFolderPass, we don't check the disabled passed

Copy link
Member Author

Choose a reason for hiding this comment

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

This also seems to bypass the -disable-branch-fold.

Any suggestions on how to proceed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the function properties error is from somewhere else. Most passes probably are not appropriately reporting cleared properties

Copy link
Contributor

Choose a reason for hiding this comment

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

What test hit the property error? I think SPIRV needs to cear NoPHIs property after its selection. It's bypassing the usual place it's cleared (though I'm not sure why it's cleared here)

Copy link
Member Author

Choose a reason for hiding this comment

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

All tests are passing with the latest version of this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this avoided after the new version of #136327?

Copy link
Member Author

Choose a reason for hiding this comment

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

This piece of code is no longer part of the PR.

this->EnableTailMerge;
MBFIWrapper MBBFreqInfo(
getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI());
BranchFolder Folder(
Expand Down Expand Up @@ -2080,3 +2091,7 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
++NumHoist;
return true;
}

MachineFunctionPass *llvm::createBranchFolderPass(bool EnableTailMerge = true) {
return new BranchFolderLegacy(EnableTailMerge);
}