1 //===-- SizeOpts.cpp - code size optimization related code ----------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains some shared code size optimization related code.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Analysis/BlockFrequencyInfo.h"
14 #include "llvm/Analysis/ProfileSummaryInfo.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Transforms/Utils/SizeOpts.h"
19 static cl::opt
<bool> ProfileGuidedSizeOpt(
20 "pgso", cl::Hidden
, cl::init(true),
21 cl::desc("Enable the profile guided size optimization. "));
23 bool llvm::shouldOptimizeForSize(Function
*F
, ProfileSummaryInfo
*PSI
,
24 BlockFrequencyInfo
*BFI
) {
26 if (!PSI
|| !BFI
|| !PSI
->hasProfileSummary())
28 return ProfileGuidedSizeOpt
&& PSI
->isFunctionColdInCallGraph(F
, *BFI
);
31 bool llvm::shouldOptimizeForSize(BasicBlock
*BB
, ProfileSummaryInfo
*PSI
,
32 BlockFrequencyInfo
*BFI
) {
34 if (!PSI
|| !BFI
|| !PSI
->hasProfileSummary())
36 return ProfileGuidedSizeOpt
&& PSI
->isColdBlock(BB
, BFI
);