]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Transforms/Utils/SizeOpts.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Transforms / Utils / SizeOpts.cpp
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/Analysis/BlockFrequencyInfo.h"
14 #include "llvm/Analysis/ProfileSummaryInfo.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Transforms/Utils/SizeOpts.h"
17 using namespace llvm;
18
19 static cl::opt<bool> ProfileGuidedSizeOpt(
20     "pgso", cl::Hidden, cl::init(true),
21     cl::desc("Enable the profile guided size optimization. "));
22
23 bool llvm::shouldOptimizeForSize(Function *F, ProfileSummaryInfo *PSI,
24                                  BlockFrequencyInfo *BFI) {
25   assert(F);
26   if (!PSI || !BFI || !PSI->hasProfileSummary())
27     return false;
28   return ProfileGuidedSizeOpt && PSI->isFunctionColdInCallGraph(F, *BFI);
29 }
30
31 bool llvm::shouldOptimizeForSize(BasicBlock *BB, ProfileSummaryInfo *PSI,
32                                  BlockFrequencyInfo *BFI) {
33   assert(BB);
34   if (!PSI || !BFI || !PSI->hasProfileSummary())
35     return false;
36   return ProfileGuidedSizeOpt && PSI->isColdBlock(BB, BFI);
37 }