LLVM  12.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 
15 using 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  "pgso-ir-pass-or-test-only", cl::Hidden, cl::init(false),
48  cl::desc("Apply the profile guided size optimizations only"
49  "to the IR passes or tests."));
50 
52  "force-pgso", cl::Hidden, cl::init(false),
53  cl::desc("Force the (profiled-guided) size optimizations. "));
54 
56  "pgso-cutoff-instr-prof", cl::Hidden, cl::init(950000), cl::ZeroOrMore,
57  cl::desc("The profile guided size optimization profile summary cutoff "
58  "for instrumentation profile."));
59 
61  "pgso-cutoff-sample-prof", cl::Hidden, cl::init(990000), cl::ZeroOrMore,
62  cl::desc("The profile guided size optimization profile summary cutoff "
63  "for sample profile."));
64 
65 namespace {
66 struct BasicBlockBFIAdapter {
67  static bool isFunctionColdInCallGraph(const Function *F,
68  ProfileSummaryInfo *PSI,
70  return PSI->isFunctionColdInCallGraph(F, BFI);
71  }
72  static bool isFunctionHotInCallGraphNthPercentile(int CutOff,
73  const Function *F,
74  ProfileSummaryInfo *PSI,
75  BlockFrequencyInfo &BFI) {
76  return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI);
77  }
78  static bool isFunctionColdInCallGraphNthPercentile(int CutOff,
79  const Function *F,
80  ProfileSummaryInfo *PSI,
81  BlockFrequencyInfo &BFI) {
82  return PSI->isFunctionColdInCallGraphNthPercentile(CutOff, F, BFI);
83  }
84  static bool isColdBlock(const BasicBlock *BB,
85  ProfileSummaryInfo *PSI,
86  BlockFrequencyInfo *BFI) {
87  return PSI->isColdBlock(BB, BFI);
88  }
89  static bool isHotBlockNthPercentile(int CutOff,
90  const BasicBlock *BB,
91  ProfileSummaryInfo *PSI,
92  BlockFrequencyInfo *BFI) {
93  return PSI->isHotBlockNthPercentile(CutOff, BB, BFI);
94  }
95  static bool isColdBlockNthPercentile(int CutOff, const BasicBlock *BB,
96  ProfileSummaryInfo *PSI,
97  BlockFrequencyInfo *BFI) {
98  return PSI->isColdBlockNthPercentile(CutOff, BB, BFI);
99  }
100 };
101 } // end anonymous namespace
102 
104  BlockFrequencyInfo *BFI,
105  PGSOQueryType QueryType) {
106  return shouldFuncOptimizeForSizeImpl<BasicBlockBFIAdapter>(F, PSI, BFI,
107  QueryType);
108 }
109 
111  BlockFrequencyInfo *BFI,
112  PGSOQueryType QueryType) {
113  assert(BB);
114  return shouldOptimizeForSizeImpl<BasicBlockBFIAdapter>(BB, PSI, BFI,
115  QueryType);
116 }
cl::opt< bool > PGSOColdCodeOnlyForPartialSamplePGO("pgso-cold-code-only-for-partial-sample-pgo", cl::Hidden, cl::init(false), cl::desc("Apply the profile guided size optimizations only " "to cold code under partial-profile sample PGO."))
cl::opt< bool > PGSOLargeWorkingSetSizeOnly("pgso-lwss-only", cl::Hidden, cl::init(true), cl::desc("Apply the profile guided size optimizations only " "if the working set size is large (except for cold code.)"))
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Analysis providing profile information.
F(f)
bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains only cold code.
cl::opt< bool > EnablePGSO("pgso", cl::Hidden, cl::init(true), cl::desc("Enable the profile guided size optimizations. "))
bool isFunctionColdInCallGraphNthPercentile(int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains cold code with regard to a given cold percentile cutoff value...
cl::opt< int > PgsoCutoffSampleProf("pgso-cutoff-sample-prof", cl::Hidden, cl::init(990000), cl::ZeroOrMore, cl::desc("The profile guided size optimization profile summary cutoff " "for sample profile."))
cl::opt< bool > PGSOIRPassOrTestOnly("pgso-ir-pass-or-test-only", cl::Hidden, cl::init(false), cl::desc("Apply the profile guided size optimizations only" "to the IR passes or tests."))
bool isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered cold.
cl::opt< bool > PGSOColdCodeOnly("pgso-cold-code-only", cl::Hidden, cl::init(false), cl::desc("Apply the profile guided size optimizations only " "to cold code."))
bool isHotBlockNthPercentile(int PercentileCutoff, const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered hot with regard to a given hot percentile cutoff value...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:434
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
cl::opt< bool > PGSOColdCodeOnlyForSamplePGO("pgso-cold-code-only-for-sample-pgo", cl::Hidden, cl::init(false), cl::desc("Apply the profile guided size optimizations only " "to cold code under sample PGO."))
bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains hot code with regard to a given hot percentile cutoff value.
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 isColdBlockNthPercentile(int PercentileCutoff, const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered cold with regard to a given cold percentile cutoff value...
cl::opt< int > PgsoCutoffInstrProf("pgso-cutoff-instr-prof", cl::Hidden, cl::init(950000), cl::ZeroOrMore, cl::desc("The profile guided size optimization profile summary cutoff " "for instrumentation profile."))
cl::opt< bool > PGSOColdCodeOnlyForInstrPGO("pgso-cold-code-only-for-instr-pgo", cl::Hidden, cl::init(false), cl::desc("Apply the profile guided size optimizations only " "to cold code under instrumentation PGO."))
cl::opt< bool > ForcePGSO("force-pgso", cl::Hidden, cl::init(false), cl::desc("Force the (profiled-guided) size optimizations. "))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
PGSOQueryType
Definition: SizeOpts.h:37