diff options
Diffstat (limited to 'llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineSink.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index 658ebd4..3293f7c 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -26,6 +26,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CFG.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" @@ -38,6 +39,7 @@ #include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachinePostDominators.h" #include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/MachineSizeOpts.h" #include "llvm/CodeGen/RegisterClassInfo.h" #include "llvm/CodeGen/RegisterPressure.h" #include "llvm/CodeGen/TargetInstrInfo.h" @@ -122,6 +124,7 @@ namespace { MachineDominatorTree *DT = nullptr; // Machine dominator tree MachinePostDominatorTree *PDT = nullptr; // Machine post dominator tree MachineCycleInfo *CI = nullptr; + ProfileSummaryInfo *PSI = nullptr; MachineBlockFrequencyInfo *MBFI = nullptr; const MachineBranchProbabilityInfo *MBPI = nullptr; AliasAnalysis *AA = nullptr; @@ -198,6 +201,7 @@ namespace { AU.addRequired<MachineBranchProbabilityInfoWrapperPass>(); AU.addPreserved<MachineCycleInfoWrapperPass>(); AU.addPreserved<MachineLoopInfoWrapperPass>(); + AU.addRequired<ProfileSummaryInfoWrapperPass>(); if (UseBlockFreqInfo) AU.addRequired<MachineBlockFrequencyInfoWrapperPass>(); AU.addRequired<TargetPassConfig>(); @@ -284,6 +288,7 @@ char &llvm::MachineSinkingID = MachineSinking::ID; INITIALIZE_PASS_BEGIN(MachineSinking, DEBUG_TYPE, "Machine code sinking", false, false) +INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(MachineCycleInfoWrapperPass) @@ -722,6 +727,7 @@ bool MachineSinking::runOnMachineFunction(MachineFunction &MF) { DT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree(); PDT = &getAnalysis<MachinePostDominatorTreeWrapperPass>().getPostDomTree(); CI = &getAnalysis<MachineCycleInfoWrapperPass>().getCycleInfo(); + PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(); MBFI = UseBlockFreqInfo ? &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI() : nullptr; @@ -1217,12 +1223,12 @@ MachineSinking::GetAllSortedSuccessors(MachineInstr &MI, MachineBasicBlock *MBB, // Sort Successors according to their cycle depth or block frequency info. llvm::stable_sort( - AllSuccs, [this](const MachineBasicBlock *L, const MachineBasicBlock *R) { + AllSuccs, [&](const MachineBasicBlock *L, const MachineBasicBlock *R) { uint64_t LHSFreq = MBFI ? MBFI->getBlockFreq(L).getFrequency() : 0; uint64_t RHSFreq = MBFI ? MBFI->getBlockFreq(R).getFrequency() : 0; - bool HasBlockFreq = LHSFreq != 0 || RHSFreq != 0; - return HasBlockFreq ? LHSFreq < RHSFreq - : CI->getCycleDepth(L) < CI->getCycleDepth(R); + if (llvm::shouldOptimizeForSize(MBB, PSI, MBFI) || !LHSFreq || !RHSFreq) + return CI->getCycleDepth(L) < CI->getCycleDepth(R); + return LHSFreq < RHSFreq; }); auto it = AllSuccessors.insert(std::make_pair(MBB, AllSuccs)); |