mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-24 13:18:17 +00:00
[Branch probability] Recompute branch weights of tail-merged basic blocks.
BranchFolderPass was not correctly setting the basic block branch weights when tail-merging created or merged blocks. This patch recomutes the weights of tail-merged blocks using the following formula: branch_weight(merged block to successor j) = sum(block_frequency(bb) * branch_probability(bb -> j)) bb is a block that is in the set of merged blocks. <rdar://problem/16256423> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215135 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/CodeGen/LivePhysRegs.h"
|
||||
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
|
||||
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||
@@ -161,6 +162,7 @@ namespace {
|
||||
const TargetLoweringBase *TLI;
|
||||
const TargetInstrInfo *TII;
|
||||
const TargetRegisterInfo *TRI;
|
||||
const MachineBlockFrequencyInfo *MBFI;
|
||||
const MachineBranchProbabilityInfo *MBPI;
|
||||
MachineRegisterInfo *MRI;
|
||||
|
||||
@@ -177,6 +179,7 @@ namespace {
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<MachineBlockFrequencyInfo>();
|
||||
AU.addRequired<MachineBranchProbabilityInfo>();
|
||||
MachineFunctionPass::getAnalysisUsage(AU);
|
||||
}
|
||||
@@ -272,6 +275,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
||||
TLI = MF.getSubtarget().getTargetLowering();
|
||||
TII = MF.getSubtarget().getInstrInfo();
|
||||
TRI = MF.getSubtarget().getRegisterInfo();
|
||||
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
|
||||
MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
|
||||
MRI = &MF.getRegInfo();
|
||||
|
||||
@@ -286,7 +290,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
||||
bool BFChange = false;
|
||||
if (!PreRegAlloc) {
|
||||
// Tail merge tend to expose more if-conversion opportunities.
|
||||
BranchFolder BF(true, false);
|
||||
BranchFolder BF(true, false, *MBFI, *MBPI);
|
||||
BFChange = BF.OptimizeFunction(MF, TII, MF.getSubtarget().getRegisterInfo(),
|
||||
getAnalysisIfAvailable<MachineModuleInfo>());
|
||||
}
|
||||
@@ -419,7 +423,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
|
||||
BBAnalysis.clear();
|
||||
|
||||
if (MadeChange && IfCvtBranchFold) {
|
||||
BranchFolder BF(false, false);
|
||||
BranchFolder BF(false, false, *MBFI, *MBPI);
|
||||
BF.OptimizeFunction(MF, TII, MF.getSubtarget().getRegisterInfo(),
|
||||
getAnalysisIfAvailable<MachineModuleInfo>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user