LLVM 20.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
15
16using namespace llvm;
17
19 "pgso", cl::Hidden, cl::init(true),
20 cl::desc("Enable the profile guided size optimizations. "));
21
23 "pgso-lwss-only", cl::Hidden, cl::init(true),
24 cl::desc("Apply the profile guided size optimizations only "
25 "if the working set size is large (except for cold code.)"));
26
28 "pgso-cold-code-only", cl::Hidden, cl::init(false),
29 cl::desc("Apply the profile guided size optimizations only "
30 "to cold code."));
31
33 "pgso-cold-code-only-for-instr-pgo", cl::Hidden, cl::init(false),
34 cl::desc("Apply the profile guided size optimizations only "
35 "to cold code under instrumentation PGO."));
36
38 "pgso-cold-code-only-for-sample-pgo", cl::Hidden, cl::init(false),
39 cl::desc("Apply the profile guided size optimizations only "
40 "to cold code under sample PGO."));
41
43 "pgso-cold-code-only-for-partial-sample-pgo", cl::Hidden, cl::init(false),
44 cl::desc("Apply the profile guided size optimizations only "
45 "to cold code under partial-profile sample PGO."));
46
48 "force-pgso", cl::Hidden, cl::init(false),
49 cl::desc("Force the (profiled-guided) size optimizations. "));
50
52 "pgso-cutoff-instr-prof", cl::Hidden, cl::init(950000),
53 cl::desc("The profile guided size optimization profile summary cutoff "
54 "for instrumentation profile."));
55
57 "pgso-cutoff-sample-prof", cl::Hidden, cl::init(990000),
58 cl::desc("The profile guided size optimization profile summary cutoff "
59 "for sample profile."));
60
61namespace {
62struct BasicBlockBFIAdapter {
63 static bool isFunctionColdInCallGraph(const Function *F,
65 BlockFrequencyInfo &BFI) {
66 return PSI->isFunctionColdInCallGraph(F, BFI);
67 }
68 static bool isFunctionHotInCallGraphNthPercentile(int CutOff,
69 const Function *F,
71 BlockFrequencyInfo &BFI) {
72 return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI);
73 }
74 static bool isFunctionColdInCallGraphNthPercentile(int CutOff,
75 const Function *F,
77 BlockFrequencyInfo &BFI) {
78 return PSI->isFunctionColdInCallGraphNthPercentile(CutOff, F, BFI);
79 }
80 static bool isColdBlock(const BasicBlock *BB,
82 BlockFrequencyInfo *BFI) {
83 return PSI->isColdBlock(BB, BFI);
84 }
85 static bool isHotBlockNthPercentile(int CutOff,
86 const BasicBlock *BB,
88 BlockFrequencyInfo *BFI) {
89 return PSI->isHotBlockNthPercentile(CutOff, BB, BFI);
90 }
91 static bool isColdBlockNthPercentile(int CutOff, const BasicBlock *BB,
93 BlockFrequencyInfo *BFI) {
94 return PSI->isColdBlockNthPercentile(CutOff, BB, BFI);
95 }
96};
97} // end anonymous namespace
98
101 PGSOQueryType QueryType) {
102 if (F->hasOptSize())
103 return true;
104 return shouldFuncOptimizeForSizeImpl(F, PSI, BFI, QueryType);
105}
106
109 PGSOQueryType QueryType) {
110 assert(BB);
111 if (BB->getParent()->hasOptSize())
112 return true;
113 return shouldOptimizeForSizeImpl(BB, PSI, BFI, QueryType);
114}
#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:61
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:219
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Definition: Function.h:707
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:443
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