Skip to content

Commit 1439764

Browse files
[CodeGen][NPM] Create method to add the branch folding pass with the option to enable tail merge
Signed-off-by: Mikhail R. Gadelha <[email protected]>
1 parent 65813e0 commit 1439764

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ namespace llvm {
257257
/// branches.
258258
extern char &BranchFolderPassID;
259259

260+
MachineFunctionPass *createBranchFolderPass(bool EnableTailMerge);
261+
260262
/// BranchRelaxation - This pass replaces branches that need to jump further
261263
/// than is supported by a branch instruction.
262264
extern char &BranchRelaxationPassID;

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ namespace {
9090

9191
/// BranchFolderPass - Wrap branch folder in a machine function pass.
9292
class BranchFolderLegacy : public MachineFunctionPass {
93+
bool EnableTailMerge;
94+
9395
public:
9496
static char ID;
9597

96-
explicit BranchFolderLegacy() : MachineFunctionPass(ID) {}
98+
explicit BranchFolderLegacy(bool EnableTailMerge = true)
99+
: MachineFunctionPass(ID), EnableTailMerge(EnableTailMerge) {}
97100

98101
bool runOnMachineFunction(MachineFunction &MF) override;
99102

@@ -152,7 +155,8 @@ bool BranchFolderLegacy::runOnMachineFunction(MachineFunction &MF) {
152155
// TailMerge can create jump into if branches that make CFG irreducible for
153156
// HW that requires structurized CFG.
154157
bool EnableTailMerge = !MF.getTarget().requiresStructuredCFG() &&
155-
PassConfig->getEnableTailMerge();
158+
PassConfig->getEnableTailMerge() &&
159+
this->EnableTailMerge;
156160
MBFIWrapper MBBFreqInfo(
157161
getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI());
158162
BranchFolder Folder(
@@ -2080,3 +2084,7 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
20802084
++NumHoist;
20812085
return true;
20822086
}
2087+
2088+
MachineFunctionPass *llvm::createBranchFolderPass(bool EnableTailMerge = true) {
2089+
return new BranchFolderLegacy(EnableTailMerge);
2090+
}

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "RISCVTargetTransformInfo.h"
1919
#include "TargetInfo/RISCVTargetInfo.h"
2020
#include "llvm/Analysis/TargetTransformInfo.h"
21+
#include "llvm/CodeGen/BranchFoldingPass.h"
2122
#include "llvm/CodeGen/GlobalISel/CSEInfo.h"
2223
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
2324
#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"

0 commit comments

Comments
 (0)