Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / llvm / lib / Transforms / Utils / SizeOpts.cpp
blobd2a400027d4b78c36d5359e97372c88eeeab6a4e
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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Transforms/Utils/SizeOpts.h"
15 using namespace llvm;
17 cl::opt<bool> EnablePGSO(
18 "pgso", cl::Hidden, cl::init(true),
19 cl::desc("Enable the profile guided size optimizations. "));
21 cl::opt<bool> PGSOLargeWorkingSetSizeOnly(
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.)"));
26 cl::opt<bool> PGSOColdCodeOnly(
27 "pgso-cold-code-only", cl::Hidden, cl::init(true),
28 cl::desc("Apply the profile guided size optimizations only "
29 "to cold code."));
31 cl::opt<bool> PGSOIRPassOrTestOnly(
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."));
36 cl::opt<bool> ForcePGSO(
37 "force-pgso", cl::Hidden, cl::init(false),
38 cl::desc("Force the (profiled-guided) size optimizations. "));
40 cl::opt<int> PgsoCutoffInstrProf(
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."));
45 cl::opt<int> PgsoCutoffSampleProf(
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."));
50 namespace {
51 struct BasicBlockBFIAdapter {
52 static bool isFunctionColdInCallGraph(const Function *F,
53 ProfileSummaryInfo *PSI,
54 BlockFrequencyInfo &BFI) {
55 return PSI->isFunctionColdInCallGraph(F, BFI);
57 static bool isFunctionHotInCallGraphNthPercentile(int CutOff,
58 const Function *F,
59 ProfileSummaryInfo *PSI,
60 BlockFrequencyInfo &BFI) {
61 return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI);
63 static bool isColdBlock(const BasicBlock *BB,
64 ProfileSummaryInfo *PSI,
65 BlockFrequencyInfo *BFI) {
66 return PSI->isColdBlock(BB, BFI);
68 static bool isHotBlockNthPercentile(int CutOff,
69 const BasicBlock *BB,
70 ProfileSummaryInfo *PSI,
71 BlockFrequencyInfo *BFI) {
72 return PSI->isHotBlockNthPercentile(CutOff, BB, BFI);
75 } // end anonymous namespace
77 bool llvm::shouldOptimizeForSize(const Function *F, ProfileSummaryInfo *PSI,
78 BlockFrequencyInfo *BFI,
79 PGSOQueryType QueryType) {
80 return shouldFuncOptimizeForSizeImpl<BasicBlockBFIAdapter>(F, PSI, BFI,
81 QueryType);
84 bool llvm::shouldOptimizeForSize(const BasicBlock *BB, ProfileSummaryInfo *PSI,
85 BlockFrequencyInfo *BFI,
86 PGSOQueryType QueryType) {
87 return shouldOptimizeForSizeImpl<BasicBlockBFIAdapter>(BB, PSI, BFI,
88 QueryType);