diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /llvm/lib/CodeGen/MachineSizeOpts.cpp | |
parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) |
Notes
Diffstat (limited to 'llvm/lib/CodeGen/MachineSizeOpts.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineSizeOpts.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineSizeOpts.cpp b/llvm/lib/CodeGen/MachineSizeOpts.cpp new file mode 100644 index 000000000000..aff67f9cfd55 --- /dev/null +++ b/llvm/lib/CodeGen/MachineSizeOpts.cpp @@ -0,0 +1,122 @@ +//===- MachineSizeOpts.cpp - code size optimization related code ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains some shared machine IR code size optimization related +// code. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/MachineSizeOpts.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" +#include "llvm/CodeGen/MachineBlockFrequencyInfo.h" + +using namespace llvm; + +extern cl::opt<bool> EnablePGSO; +extern cl::opt<bool> PGSOLargeWorkingSetSizeOnly; +extern cl::opt<bool> ForcePGSO; +extern cl::opt<int> PgsoCutoffInstrProf; +extern cl::opt<int> PgsoCutoffSampleProf; + +namespace machine_size_opts_detail { + +/// Like ProfileSummaryInfo::isColdBlock but for MachineBasicBlock. +bool isColdBlock(const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + auto Count = MBFI->getBlockProfileCount(MBB); + return Count && PSI->isColdCount(*Count); +} + +/// Like ProfileSummaryInfo::isHotBlockNthPercentile but for MachineBasicBlock. +static bool isHotBlockNthPercentile(int PercentileCutoff, + const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + auto Count = MBFI->getBlockProfileCount(MBB); + return Count && PSI->isHotCountNthPercentile(PercentileCutoff, *Count); +} + +/// Like ProfileSummaryInfo::isFunctionColdInCallGraph but for +/// MachineFunction. +bool isFunctionColdInCallGraph( + const MachineFunction *MF, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo &MBFI) { + if (auto FunctionCount = MF->getFunction().getEntryCount()) + if (!PSI->isColdCount(FunctionCount.getCount())) + return false; + for (const auto &MBB : *MF) + if (!isColdBlock(&MBB, PSI, &MBFI)) + return false; + return true; +} + +/// Like ProfileSummaryInfo::isFunctionHotInCallGraphNthPercentile but for +/// MachineFunction. +bool isFunctionHotInCallGraphNthPercentile( + int PercentileCutoff, + const MachineFunction *MF, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo &MBFI) { + if (auto FunctionCount = MF->getFunction().getEntryCount()) + if (PSI->isHotCountNthPercentile(PercentileCutoff, + FunctionCount.getCount())) + return true; + for (const auto &MBB : *MF) + if (isHotBlockNthPercentile(PercentileCutoff, &MBB, PSI, &MBFI)) + return true; + return false; +} +} // namespace machine_size_opts_detail + +namespace { +struct MachineBasicBlockBFIAdapter { + static bool isFunctionColdInCallGraph(const MachineFunction *MF, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo &MBFI) { + return machine_size_opts_detail::isFunctionColdInCallGraph(MF, PSI, MBFI); + } + static bool isFunctionHotInCallGraphNthPercentile( + int CutOff, + const MachineFunction *MF, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo &MBFI) { + return machine_size_opts_detail::isFunctionHotInCallGraphNthPercentile( + CutOff, MF, PSI, MBFI); + } + static bool isColdBlock(const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + return machine_size_opts_detail::isColdBlock(MBB, PSI, MBFI); + } + static bool isHotBlockNthPercentile(int CutOff, + const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI) { + return machine_size_opts_detail::isHotBlockNthPercentile( + CutOff, MBB, PSI, MBFI); + } +}; +} // end anonymous namespace + +bool llvm::shouldOptimizeForSize(const MachineFunction *MF, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI, + PGSOQueryType QueryType) { + return shouldFuncOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>( + MF, PSI, MBFI, QueryType); +} + +bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB, + ProfileSummaryInfo *PSI, + const MachineBlockFrequencyInfo *MBFI, + PGSOQueryType QueryType) { + return shouldOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>( + MBB, PSI, MBFI, QueryType); +} |