LLVM  14.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  "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), cl::ZeroOrMore,
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), cl::ZeroOrMore,
57  cl::desc("The profile guided size optimization profile summary cutoff "
58  "for sample profile."));
59 
60 namespace {
61 struct BasicBlockBFIAdapter {
62  static bool isFunctionColdInCallGraph(const Function *F,
63  ProfileSummaryInfo *PSI,
65  return PSI->isFunctionColdInCallGraph(F, BFI);
66  }
67  static bool isFunctionHotInCallGraphNthPercentile(int CutOff,
68  const Function *F,
69  ProfileSummaryInfo *PSI,
71  return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI);
72  }
73  static bool isFunctionColdInCallGraphNthPercentile(int CutOff,
74  const Function *F,
75  ProfileSummaryInfo *PSI,
77  return PSI->isFunctionColdInCallGraphNthPercentile(CutOff, F, BFI);
78  }
79  static bool isColdBlock(const BasicBlock *BB,
80  ProfileSummaryInfo *PSI,
82  return PSI->isColdBlock(BB, BFI);
83  }
84  static bool isHotBlockNthPercentile(int CutOff,
85  const BasicBlock *BB,
86  ProfileSummaryInfo *PSI,
88  return PSI->isHotBlockNthPercentile(CutOff, BB, BFI);
89  }
90  static bool isColdBlockNthPercentile(int CutOff, const BasicBlock *BB,
91  ProfileSummaryInfo *PSI,
93  return PSI->isColdBlockNthPercentile(CutOff, BB, BFI);
94  }
95 };
96 } // end anonymous namespace
97 
100  PGSOQueryType QueryType) {
101  return shouldFuncOptimizeForSizeImpl<BasicBlockBFIAdapter>(F, PSI, BFI,
102  QueryType);
103 }
104 
107  PGSOQueryType QueryType) {
108  assert(BB);
109  return shouldOptimizeForSizeImpl<BasicBlockBFIAdapter>(BB, PSI, BFI,
110  QueryType);
111 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::ProfileSummaryInfo::isColdBlockNthPercentile
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.
Definition: ProfileSummaryInfo.cpp:353
llvm::Function
Definition: Function.h:62
SizeOpts.h
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::EnablePGSO
cl::opt< bool > EnablePGSO
llvm::PGSOColdCodeOnlyForInstrPGO
cl::opt< bool > PGSOColdCodeOnlyForInstrPGO
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
llvm::shouldOptimizeForSize
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.
Definition: MachineSizeOpts.cpp:183
llvm::ProfileSummaryInfo::isHotBlockNthPercentile
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.
Definition: ProfileSummaryInfo.cpp:348
llvm::PGSOColdCodeOnlyForSamplePGO
cl::opt< bool > PGSOColdCodeOnlyForSamplePGO
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::cl::ZeroOrMore
@ ZeroOrMore
Definition: CommandLine.h:120
llvm::cl::opt< bool >
llvm::PgsoCutoffInstrProf
cl::opt< int > PgsoCutoffInstrProf
llvm::ProfileSummaryInfo::isFunctionHotInCallGraphNthPercentile
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.
Definition: ProfileSummaryInfo.cpp:207
llvm::PGSOQueryType
PGSOQueryType
Definition: SizeOpts.h:35
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:441
llvm::ForcePGSO
cl::opt< bool > ForcePGSO
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
isColdBlock
static bool isColdBlock(const MachineBasicBlock &MBB, const MachineBlockFrequencyInfo *MBFI, ProfileSummaryInfo *PSI)
Definition: MachineFunctionSplitter.cpp:81
llvm::ProfileSummaryInfo::isFunctionColdInCallGraphNthPercentile
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.
Definition: ProfileSummaryInfo.cpp:213
llvm::AMDGPUISD::BFI
@ BFI
Definition: AMDGPUISelLowering.h:421
llvm::PGSOLargeWorkingSetSizeOnly
cl::opt< bool > PGSOLargeWorkingSetSizeOnly
llvm::PGSOColdCodeOnly
cl::opt< bool > PGSOColdCodeOnly
llvm::ProfileSummaryInfo::isFunctionColdInCallGraph
bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI) const
Returns true if F contains only cold code.
Definition: ProfileSummaryInfo.cpp:143
llvm::ProfileSummaryInfo::isColdBlock
bool isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) const
Returns true if BasicBlock BB is considered cold.
Definition: ProfileSummaryInfo.cpp:332
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::PgsoCutoffSampleProf
cl::opt< int > PgsoCutoffSampleProf
llvm::cl::desc
Definition: CommandLine.h:412
llvm::PGSOColdCodeOnlyForPartialSamplePGO
cl::opt< bool > PGSOColdCodeOnlyForPartialSamplePGO