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
13#include "llvm/Transforms/Utils/SizeOpts.h"
14#include "llvm/Analysis/BlockFrequencyInfo.h"
15
16using namespace llvm;
17
18cl::opt<bool> llvm::EnablePGSO(
19 "pgso", cl::Hidden, cl::init(Val: true),
20 cl::desc("Enable the profile guided size optimizations. "));
21
22cl::opt<bool> llvm::PGSOLargeWorkingSetSizeOnly(
23 "pgso-lwss-only", cl::Hidden, cl::init(Val: true),
24 cl::desc("Apply the profile guided size optimizations only "
25 "if the working set size is large (except for cold code.)"));
26
27cl::opt<bool> llvm::PGSOColdCodeOnly(
28 "pgso-cold-code-only", cl::Hidden, cl::init(Val: false),
29 cl::desc("Apply the profile guided size optimizations only "
30 "to cold code."));
31
32cl::opt<bool> llvm::PGSOColdCodeOnlyForInstrPGO(
33 "pgso-cold-code-only-for-instr-pgo", cl::Hidden, cl::init(Val: false),
34 cl::desc("Apply the profile guided size optimizations only "
35 "to cold code under instrumentation PGO."));
36
37cl::opt<bool> llvm::PGSOColdCodeOnlyForSamplePGO(
38 "pgso-cold-code-only-for-sample-pgo", cl::Hidden, cl::init(Val: false),
39 cl::desc("Apply the profile guided size optimizations only "
40 "to cold code under sample PGO."));
41
42cl::opt<bool> llvm::PGSOColdCodeOnlyForPartialSamplePGO(
43 "pgso-cold-code-only-for-partial-sample-pgo", cl::Hidden, cl::init(Val: false),
44 cl::desc("Apply the profile guided size optimizations only "
45 "to cold code under partial-profile sample PGO."));
46
47cl::opt<bool> llvm::ForcePGSO(
48 "force-pgso", cl::Hidden, cl::init(Val: false),
49 cl::desc("Force the (profiled-guided) size optimizations. "));
50
51cl::opt<int> llvm::PgsoCutoffInstrProf(
52 "pgso-cutoff-instr-prof", cl::Hidden, cl::init(Val: 950000),
53 cl::desc("The profile guided size optimization profile summary cutoff "
54 "for instrumentation profile."));
55
56cl::opt<int> llvm::PgsoCutoffSampleProf(
57 "pgso-cutoff-sample-prof", cl::Hidden, cl::init(Val: 990000),
58 cl::desc("The profile guided size optimization profile summary cutoff "
59 "for sample profile."));
60
61bool llvm::shouldOptimizeForSize(const Function *F, ProfileSummaryInfo *PSI,
62 BlockFrequencyInfo *BFI,
63 PGSOQueryType QueryType) {
64 if (F->hasOptSize())
65 return true;
66 return shouldFuncOptimizeForSizeImpl(F, PSI, BFI, QueryType);
67}
68
69bool llvm::shouldOptimizeForSize(const BasicBlock *BB, ProfileSummaryInfo *PSI,
70 BlockFrequencyInfo *BFI,
71 PGSOQueryType QueryType) {
72 assert(BB);
73 if (BB->getParent()->hasOptSize())
74 return true;
75 return shouldOptimizeForSizeImpl(BBOrBlockFreq: BB, PSI, BFI, QueryType);
76}
77