[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / Transforms / Utils / SizeOpts.cpp
blob1519751197d24dd129c82621eaf33952e4532576
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/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;
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) {
25 assert(F);
26 if (!PSI || !BFI || !PSI->hasProfileSummary())
27 return false;
28 return ProfileGuidedSizeOpt && PSI->isFunctionColdInCallGraph(F, *BFI);
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);