33 explicit BranchFolder(
bool DefaultEnableTailMerge,
bool CommonHoist,
39 unsigned MinTailLength = 0);
47 bool AfterPlacement =
false);
53 EnableBasicBlockReordering =
Enable;
57 class MergePotentialsElt {
66 unsigned getHash()
const {
return Hash; }
67 MachineBasicBlock *getBlock()
const {
return Block; }
69 void setBlock(MachineBasicBlock *
MBB) {
73 const DebugLoc &getBranchDebugLoc() {
return BranchDebugLoc; }
75 bool operator<(
const MergePotentialsElt &)
const;
78 using MPIterator = std::vector<MergePotentialsElt>::iterator;
80 std::vector<MergePotentialsElt> MergePotentials;
81 SmallPtrSet<const MachineBasicBlock*, 2> TriedMerging;
82 DenseMap<const MachineBasicBlock *, int> EHScopeMembership;
86 MachineBasicBlock::iterator TailStartPos;
89 SameTailElt(MPIterator mp, MachineBasicBlock::iterator tsp)
90 : MPIter(mp), TailStartPos(tsp) {}
92 MPIterator getMPIter()
const {
96 MergePotentialsElt &getMergePotentialsElt()
const {
100 MachineBasicBlock::iterator getTailStartPos()
const {
104 unsigned getHash()
const {
105 return getMergePotentialsElt().getHash();
108 MachineBasicBlock *getBlock()
const {
109 return getMergePotentialsElt().getBlock();
112 bool tailIsWholeBlock()
const {
113 return TailStartPos == getBlock()->begin();
116 void setBlock(MachineBasicBlock *
MBB) {
117 getMergePotentialsElt().setBlock(
MBB);
120 void setTailStartPos(MachineBasicBlock::iterator Pos) {
124 std::vector<SameTailElt> SameTails;
126 bool AfterBlockPlacement =
false;
127 bool EnableTailMerge =
false;
128 bool EnableHoistCommonCode =
false;
129 bool EnableBasicBlockReordering =
false;
130 bool UpdateLiveIns =
false;
131 unsigned MinCommonTailLength;
132 const TargetInstrInfo *
TII =
nullptr;
133 const MachineRegisterInfo *MRI =
nullptr;
134 const TargetRegisterInfo *
TRI =
nullptr;
135 MachineLoopInfo *MLI =
nullptr;
136 LivePhysRegs LiveRegs;
139 MBFIWrapper &MBBFreqInfo;
140 const MachineBranchProbabilityInfo &MBPI;
141 ProfileSummaryInfo *PSI;
143 bool TailMergeBlocks(MachineFunction &MF);
144 bool TryTailMergeBlocks(MachineBasicBlock* SuccBB,
145 MachineBasicBlock* PredBB,
146 unsigned MinCommonTailLength);
147 void setCommonTailEdgeWeights(MachineBasicBlock &TailMBB);
151 void replaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
152 MachineBasicBlock &NewDest);
157 MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
158 MachineBasicBlock::iterator BBI1,
159 const BasicBlock *BB);
170 unsigned ComputeSameTails(
unsigned CurHash,
unsigned minCommonTailLength,
171 MachineBasicBlock *SuccBB,
172 MachineBasicBlock *PredBB);
176 void RemoveBlocksWithHash(
unsigned CurHash, MachineBasicBlock *SuccBB,
177 MachineBasicBlock *PredBB,
178 const DebugLoc &BranchDL);
182 bool CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
183 MachineBasicBlock *SuccBB,
184 unsigned maxCommonTailLength,
185 unsigned &commonTailIndex);
189 void mergeCommonTails(
unsigned commonTailIndex);
191 bool OptimizeBranches(MachineFunction &MF);
195 bool OptimizeBlock(MachineBasicBlock *
MBB);
199 void RemoveDeadBlock(MachineBasicBlock *
MBB);
203 bool HoistCommonCode(MachineFunction &MF);
207 bool HoistCommonCodeInSuccs(MachineBasicBlock *
MBB);
bool OptimizeFunction(MachineFunction &MF, const TargetInstrInfo *tii, const TargetRegisterInfo *tri, MachineLoopInfo *mli=nullptr, bool AfterPlacement=false)
Perhaps branch folding, tail merging and other CFG optimizations on the given function.