LLVM  10.0.0
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(true),
28  cl::desc("Apply the profile guided size optimizations only "
29  "to cold code."));
30 
32  "pgso-ir-pass-or-test-only", cl::Hidden, cl::init(false),
33  cl::desc("Apply the profile guided size optimizations only"
34  "to the IR passes or tests."));
35 
37  "force-pgso", cl::Hidden, cl::init(false),
38  cl::desc("Force the (profiled-guided) size optimizations. "));
39 
41  "pgso-cutoff-instr-prof", cl::Hidden, cl::init(250000), cl::ZeroOrMore,
42  cl::desc("The profile guided size optimization profile summary cutoff "
43  "for instrumentation profile."));
44 
46  "pgso-cutoff-sample-prof", cl::Hidden, cl::init(800000), cl::ZeroOrMore,
47  cl::desc("The profile guided size optimization profile summary cutoff "
48  "for sample profile."));
49 
50 namespace {
51 struct BasicBlockBFIAdapter {
52  static bool isFunctionColdInCallGraph(const Function *F,
53  ProfileSummaryInfo *PSI,
55  return PSI->isFunctionColdInCallGraph(F, BFI);
56  }
57  static bool isFunctionHotInCallGraphNthPercentile(int CutOff,
58  const Function *F,
59  ProfileSummaryInfo *PSI,
60  BlockFrequencyInfo &BFI) {
61  return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI);
62  }
63  static bool isColdBlock(const BasicBlock *BB,
64  ProfileSummaryInfo *PSI,
65  BlockFrequencyInfo *BFI) {
66  return PSI->isColdBlock(BB, BFI);
67  }
68  static bool isHotBlockNthPercentile(int CutOff,
69  const BasicBlock *BB,
70  ProfileSummaryInfo *PSI,
71  BlockFrequencyInfo *BFI) {
72  return PSI->isHotBlockNthPercentile(CutOff, BB, BFI);
73  }
74 };
75 } // end anonymous namespace
76 
78  BlockFrequencyInfo *BFI,
79  PGSOQueryType QueryType) {
80  return shouldFuncOptimizeForSizeImpl<BasicBlockBFIAdapter>(F, PSI, BFI,
81  QueryType);
82 }
83 
85  BlockFrequencyInfo *BFI,
86  PGSOQueryType QueryType) {
87  return shouldOptimizeForSizeImpl<BasicBlockBFIAdapter>(BB, PSI, BFI,
88  QueryType);
89 }
bool isFunctionColdInCallGraph(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo &MBFI)
Like ProfileSummaryInfo::isFunctionColdInCallGraph but for MachineFunction.
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.
cl::opt< int > PgsoCutoffInstrProf("pgso-cutoff-instr-prof", cl::Hidden, cl::init(250000), cl::ZeroOrMore, cl::desc("The profile guided size optimization profile summary cutoff " "for instrumentation profile."))
bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI)
Returns true if F contains hot code with regard to a given hot percentile cutoff value.
F(f)
static bool isHotBlockNthPercentile(int PercentileCutoff, const MachineBasicBlock *MBB, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *MBFI)
Like ProfileSummaryInfo::isHotBlockNthPercentile but for MachineBasicBlock.
cl::opt< bool > PGSOColdCodeOnly("pgso-cold-code-only", cl::Hidden, cl::init(true), cl::desc("Apply the profile guided size optimizations only " "to cold code."))
cl::opt< bool > EnablePGSO("pgso", cl::Hidden, cl::init(true), cl::desc("Enable the profile guided size optimizations. "))
bool isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI)
Returns true if BasicBlock BB is considered cold.
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."))
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:435
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
bool isHotBlockNthPercentile(int PercentileCutoff, const BasicBlock *BB, BlockFrequencyInfo *BFI)
Returns true if BasicBlock BB is considered hot with regard to a given hot percentile cutoff value...
cl::opt< int > PgsoCutoffSampleProf("pgso-cutoff-sample-prof", cl::Hidden, cl::init(800000), cl::ZeroOrMore, cl::desc("The profile guided size optimization profile summary cutoff " "for sample profile."))
bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI)
Returns true if F contains only cold code.
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...
cl::opt< bool > ForcePGSO("force-pgso", cl::Hidden, cl::init(false), cl::desc("Force the (profiled-guided) size optimizations. "))
bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff, const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo &MBFI)
Like ProfileSummaryInfo::isFunctionHotInCallGraphNthPercentile but for MachineFunction.
PGSOQueryType
Definition: SizeOpts.h:35
bool isColdBlock(const MachineBasicBlock *MBB, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *MBFI)
Like ProfileSummaryInfo::isColdBlock but for MachineBasicBlock.