xref: /src/contrib/llvm-project/llvm/lib/CodeGen/MachineSizeOpts.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1706b4fc4SDimitry Andric //===- MachineSizeOpts.cpp - code size optimization related code ----------===//
2706b4fc4SDimitry Andric //
3706b4fc4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4706b4fc4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5706b4fc4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6706b4fc4SDimitry Andric //
7706b4fc4SDimitry Andric //===----------------------------------------------------------------------===//
8706b4fc4SDimitry Andric //
9706b4fc4SDimitry Andric // This file contains some shared machine IR code size optimization related
10706b4fc4SDimitry Andric // code.
11706b4fc4SDimitry Andric //
12706b4fc4SDimitry Andric //===----------------------------------------------------------------------===//
13706b4fc4SDimitry Andric 
14706b4fc4SDimitry Andric #include "llvm/CodeGen/MachineSizeOpts.h"
15cfca06d7SDimitry Andric #include "llvm/CodeGen/MBFIWrapper.h"
16706b4fc4SDimitry Andric #include "llvm/Analysis/ProfileSummaryInfo.h"
17706b4fc4SDimitry Andric #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
18706b4fc4SDimitry Andric 
19706b4fc4SDimitry Andric using namespace llvm;
20706b4fc4SDimitry Andric 
21706b4fc4SDimitry Andric extern cl::opt<bool> EnablePGSO;
22706b4fc4SDimitry Andric extern cl::opt<bool> PGSOLargeWorkingSetSizeOnly;
23706b4fc4SDimitry Andric extern cl::opt<bool> ForcePGSO;
24706b4fc4SDimitry Andric extern cl::opt<int> PgsoCutoffInstrProf;
25706b4fc4SDimitry Andric extern cl::opt<int> PgsoCutoffSampleProf;
26706b4fc4SDimitry Andric 
shouldOptimizeForSize(const MachineFunction * MF,ProfileSummaryInfo * PSI,const MachineBlockFrequencyInfo * MBFI,PGSOQueryType QueryType)27706b4fc4SDimitry Andric bool llvm::shouldOptimizeForSize(const MachineFunction *MF,
28706b4fc4SDimitry Andric                                  ProfileSummaryInfo *PSI,
29706b4fc4SDimitry Andric                                  const MachineBlockFrequencyInfo *MBFI,
30706b4fc4SDimitry Andric                                  PGSOQueryType QueryType) {
317fa27ce4SDimitry Andric   return shouldFuncOptimizeForSizeImpl(MF, PSI, MBFI, QueryType);
32706b4fc4SDimitry Andric }
33706b4fc4SDimitry Andric 
shouldOptimizeForSize(const MachineBasicBlock * MBB,ProfileSummaryInfo * PSI,const MachineBlockFrequencyInfo * MBFI,PGSOQueryType QueryType)34706b4fc4SDimitry Andric bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,
35706b4fc4SDimitry Andric                                  ProfileSummaryInfo *PSI,
36706b4fc4SDimitry Andric                                  const MachineBlockFrequencyInfo *MBFI,
37706b4fc4SDimitry Andric                                  PGSOQueryType QueryType) {
38cfca06d7SDimitry Andric   assert(MBB);
397fa27ce4SDimitry Andric   return shouldOptimizeForSizeImpl(MBB, PSI, MBFI, QueryType);
40706b4fc4SDimitry Andric }
41cfca06d7SDimitry Andric 
shouldOptimizeForSize(const MachineBasicBlock * MBB,ProfileSummaryInfo * PSI,MBFIWrapper * MBFIW,PGSOQueryType QueryType)42cfca06d7SDimitry Andric bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,
43cfca06d7SDimitry Andric                                  ProfileSummaryInfo *PSI,
44cfca06d7SDimitry Andric                                  MBFIWrapper *MBFIW,
45cfca06d7SDimitry Andric                                  PGSOQueryType QueryType) {
46cfca06d7SDimitry Andric   assert(MBB);
47cfca06d7SDimitry Andric   if (!PSI || !MBFIW)
48cfca06d7SDimitry Andric     return false;
49cfca06d7SDimitry Andric   BlockFrequency BlockFreq = MBFIW->getBlockFreq(MBB);
507fa27ce4SDimitry Andric   return shouldOptimizeForSizeImpl(BlockFreq, PSI, &MBFIW->getMBFI(),
517fa27ce4SDimitry Andric                                    QueryType);
52cfca06d7SDimitry Andric }
53