This repository has been archived by the owner on Jan 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: (Split of off D67120) SizeOpts/MachineSizeOpts changes for profile guided size optimization. Reviewers: davidxl Subscribers: mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69070 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375254 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
1 parent
d694690
commit 1794a21
Showing
15 changed files
with
661 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===- MachineSizeOpts.h - machine size optimization ------------*- C++ -*-===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef LLVM_CODEGEN_MACHINE_SIZEOPTS_H | ||
#define LLVM_CODEGEN_MACHINE_SIZEOPTS_H | ||
|
||
#include "llvm/Transforms/Utils/SizeOpts.h" | ||
|
||
namespace llvm { | ||
|
||
class ProfileSummaryInfo; | ||
class MachineBasicBlock; | ||
class MachineBlockFrequencyInfo; | ||
class MachineFunction; | ||
|
||
/// Returns true if machine function \p MF is suggested to be size-optimized | ||
/// base on the profile. | ||
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, | ||
const MachineBlockFrequencyInfo *BFI); | ||
/// Returns true if machine basic block \p MBB is suggested to be size-optimized | ||
/// base on the profile. | ||
bool shouldOptimizeForSize(const MachineBasicBlock *MBB, | ||
ProfileSummaryInfo *PSI, | ||
const MachineBlockFrequencyInfo *MBFI); | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_CODEGEN_MACHINE_SIZEOPTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
//===- 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) { | ||
return shouldFuncOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>( | ||
MF, PSI, MBFI); | ||
} | ||
|
||
bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB, | ||
ProfileSummaryInfo *PSI, | ||
const MachineBlockFrequencyInfo *MBFI) { | ||
return shouldOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>( | ||
MBB, PSI, MBFI); | ||
} |
Oops, something went wrong.