LLVM 19.0.0git
SizeOpts.cpp
Go to the documentation of this file.
1//===-- SizeOpts.cpp - code size optimization related code ----------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains some shared code size optimization related code.
10//
11//===----------------------------------------------------------------------===//
12
14
15using namespace llvm;
16
18 "pgso", cl::Hidden, cl::init(true),
19 cl::desc("Enable the profile guided size optimizations. "));
20
22 "pgso-lwss-only", cl::Hidden, cl::init(true),
23 cl::desc("Apply the profile guided size optimizations only "
24 "if the working set size is large (except for cold code.)"));
25
27 "pgso-cold-code-only", cl::Hidden, cl::init(false),
28 cl::desc("Apply the profile guided size optimizations only "
29 "to cold code."));
30
32 "pgso-cold-code-only-for-instr-pgo", cl::Hidden, cl::init(false),
33 cl::desc("Apply the profile guided size optimizations only "
34 "to cold code under instrumentation PGO."));
35
37 "pgso-cold-code-only-for-sample-pgo", cl::Hidden, cl::init(false),
38 cl::desc("Apply the profile guided size optimizations only "
39 "to cold code under sample PGO."));
40
42 "pgso-cold-code-only-for-partial-sample-pgo", cl::Hidden, cl::init(false),
43 cl::desc("Apply the profile guided size optimizations only "
44 "to cold code under partial-profile sample PGO."));
45
47 "force-pgso", cl::Hidden, cl::init(false),
48 cl::desc("Force the (profiled-guided) size optimizations. "));
49
51 "pgso-cutoff-instr-prof", cl::Hidden, cl::init(950000),
52 cl::desc("The profile guided size optimization profile summary cutoff "
53 "for instrumentation profile."));
54
56 "pgso-cutoff-sample-prof", cl::Hidden, cl::init(990000),
57 cl::desc("The profile guided size optimization profile summary cutoff "
58 "for sample profile."));
59
60namespace {
61struct BasicBlockBFIAdapter {
62 static bool isFunctionColdInCallGraph(const Function *F,
64 BlockFrequencyInfo &BFI) {
65 return PSI->isFunctionColdInCallGraph(F, BFI);
66 }
67 static bool isFunctionHotInCallGraphNthPercentile(int CutOff,
68 const Function *F,
70 BlockFrequencyInfo &BFI) {
71 return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI);
72 }
73 static bool isFunctionColdInCallGraphNthPercentile(int CutOff,
74 const Function *F,
76 BlockFrequencyInfo &BFI) {
77 return PSI->isFunctionColdInCallGraphNthPercentile(CutOff, F, BFI);
78 }
79 static bool isColdBlock(const BasicBlock *BB,
81 BlockFrequencyInfo *BFI) {
82 return PSI->isColdBlock(BB, BFI);
83 }
84 static bool isHotBlockNthPercentile(int CutOff,
85 const BasicBlock *BB,
87 BlockFrequencyInfo *BFI) {
88 return PSI->isHotBlockNthPercentile(CutOff, BB, BFI);
89 }
90 static bool isColdBlockNthPercentile(int CutOff, const BasicBlock *BB,
92 BlockFrequencyInfo *BFI) {
93 return PSI->isColdBlockNthPercentile(CutOff, BB, BFI);
94 }
95};
96} // end anonymous namespace
97
100 PGSOQueryType QueryType) {
101 return shouldFuncOptimizeForSizeImpl(F, PSI, BFI, QueryType);
102}
103
106 PGSOQueryType QueryType) {
107 assert(BB);
108 return shouldOptimizeForSizeImpl(BB, PSI, BFI, QueryType);
109}
#define F(x, y, z)
Definition: MD5.cpp:55
static bool isColdBlock(const MachineBasicBlock &MBB, const MachineBlockFrequencyInfo *MBFI, ProfileSummaryInfo *PSI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing profile information.
bool isHotBlockNthPercentile(int PercentileCutoff, const BBType *BB, BFIT *BFI) const
bool isFunctionColdInCallGraph(const FuncT *F, BFIT &BFI) const
Returns true if F contains only cold code.
bool isFunctionColdInCallGraphNthPercentile(int PercentileCutoff, const FuncT *F, BFIT &BFI) const
Returns true if F contains cold code with regard to a given cold percentile cutoff value.
bool isColdBlock(const BBType *BB, BFIT *BFI) const
Returns true if BasicBlock BB is considered cold.
bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const FuncT *F, BFIT &BFI) const
Returns true if F contains hot code with regard to a given hot percentile cutoff value.
bool isColdBlockNthPercentile(int PercentileCutoff, const BBType *BB, BFIT *BFI) const
Returns true if BasicBlock BB is considered cold with regard to a given cold percentile cutoff value.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
cl::opt< bool > PGSOColdCodeOnlyForSamplePGO
cl::opt< bool > PGSOColdCodeOnlyForInstrPGO
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI, BFIT *BFI, PGSOQueryType QueryType)
Definition: SizeOpts.h:51
cl::opt< int > PgsoCutoffSampleProf
cl::opt< bool > EnablePGSO
cl::opt< bool > PGSOColdCodeOnlyForPartialSamplePGO
cl::opt< int > PgsoCutoffInstrProf
bool shouldOptimizeForSizeImpl(BlockTOrBlockFreq BBOrBlockFreq, ProfileSummaryInfo *PSI, BFIT *BFI, PGSOQueryType QueryType)
Definition: SizeOpts.h:72
cl::opt< bool > ForcePGSO
cl::opt< bool > PGSOLargeWorkingSetSizeOnly
PGSOQueryType
Definition: SizeOpts.h:34
cl::opt< bool > PGSOColdCodeOnly