34 explicit BranchFolder(
bool DefaultEnableTailMerge,
bool CommonHoist,
40 unsigned MinTailLength = 0);
48 bool AfterPlacement =
false);
54 EnableBasicBlockReordering =
Enable;
58 class MergePotentialsElt {
67 unsigned getHash()
const {
return Hash; }
68 MachineBasicBlock *getBlock()
const {
return Block; }
70 void setBlock(MachineBasicBlock *
MBB) {
74 const DebugLoc &getBranchDebugLoc() {
return BranchDebugLoc; }
76 bool operator<(
const MergePotentialsElt &)
const;
79 using MPIterator = std::vector<MergePotentialsElt>::iterator;
81 std::vector<MergePotentialsElt> MergePotentials;
82 SmallPtrSet<const MachineBasicBlock*, 2> TriedMerging;
83 DenseMap<const MachineBasicBlock *, int> EHScopeMembership;
87 MachineBasicBlock::iterator TailStartPos;
90 SameTailElt(MPIterator mp, MachineBasicBlock::iterator tsp)
91 : MPIter(mp), TailStartPos(tsp) {}
93 MPIterator getMPIter()
const {
97 MergePotentialsElt &getMergePotentialsElt()
const {
101 MachineBasicBlock::iterator getTailStartPos()
const {
105 unsigned getHash()
const {
106 return getMergePotentialsElt().getHash();
109 MachineBasicBlock *getBlock()
const {
110 return getMergePotentialsElt().getBlock();
113 bool tailIsWholeBlock()
const {
114 return TailStartPos == getBlock()->begin();
117 void setBlock(MachineBasicBlock *
MBB) {
118 getMergePotentialsElt().setBlock(
MBB);
121 void setTailStartPos(MachineBasicBlock::iterator Pos) {
125 std::vector<SameTailElt> SameTails;
127 const CodeGenOptions *Opts =
nullptr;
128 bool AfterBlockPlacement =
false;
129 bool EnableTailMerge =
false;
130 bool EnableHoistCommonCode =
false;
131 bool EnableBasicBlockReordering =
false;
132 bool UpdateLiveIns =
false;
133 unsigned MinCommonTailLength;
134 const TargetInstrInfo *
TII =
nullptr;
135 const MachineRegisterInfo *
MRI =
nullptr;
136 const TargetRegisterInfo *
TRI =
nullptr;
137 MachineLoopInfo *MLI =
nullptr;
138 LivePhysRegs LiveRegs;
141 MBFIWrapper &MBBFreqInfo;
142 const MachineBranchProbabilityInfo &MBPI;
143 ProfileSummaryInfo *PSI;
145 bool TailMergeBlocks(MachineFunction &MF);
146 bool TryTailMergeBlocks(MachineBasicBlock* SuccBB,
147 MachineBasicBlock* PredBB,
148 unsigned MinCommonTailLength);
149 void setCommonTailEdgeWeights(MachineBasicBlock &TailMBB);
153 void replaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
154 MachineBasicBlock &NewDest);
159 MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
160 MachineBasicBlock::iterator BBI1,
161 const BasicBlock *BB);
172 unsigned ComputeSameTails(
unsigned CurHash,
unsigned minCommonTailLength,
173 MachineBasicBlock *SuccBB,
174 MachineBasicBlock *PredBB);
178 void RemoveBlocksWithHash(
unsigned CurHash, MachineBasicBlock *SuccBB,
179 MachineBasicBlock *PredBB,
180 const DebugLoc &BranchDL);
184 bool CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
185 MachineBasicBlock *SuccBB,
186 unsigned maxCommonTailLength,
187 unsigned &commonTailIndex);
191 void mergeCommonTails(
unsigned commonTailIndex);
193 bool OptimizeBranches(MachineFunction &MF);
197 bool OptimizeBlock(MachineBasicBlock *
MBB);
201 void RemoveDeadBlock(MachineBasicBlock *
MBB);
205 bool HoistCommonCode(MachineFunction &MF);
209 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.