1480093f4SDimitry Andric //===- MachineSizeOpts.cpp - code size optimization related code ----------===//
2480093f4SDimitry Andric //
3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6480093f4SDimitry Andric //
7480093f4SDimitry Andric //===----------------------------------------------------------------------===//
8480093f4SDimitry Andric //
9480093f4SDimitry Andric // This file contains some shared machine IR code size optimization related
10480093f4SDimitry Andric // code.
11480093f4SDimitry Andric //
12480093f4SDimitry Andric //===----------------------------------------------------------------------===//
13480093f4SDimitry Andric
14480093f4SDimitry Andric #include "llvm/CodeGen/MachineSizeOpts.h"
155ffd83dbSDimitry Andric #include "llvm/CodeGen/MBFIWrapper.h"
16480093f4SDimitry Andric #include "llvm/Analysis/ProfileSummaryInfo.h"
17480093f4SDimitry Andric #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
18480093f4SDimitry Andric
19480093f4SDimitry Andric using namespace llvm;
20480093f4SDimitry Andric
21480093f4SDimitry Andric extern cl::opt<bool> EnablePGSO;
22480093f4SDimitry Andric extern cl::opt<bool> PGSOLargeWorkingSetSizeOnly;
23480093f4SDimitry Andric extern cl::opt<bool> ForcePGSO;
24480093f4SDimitry Andric extern cl::opt<int> PgsoCutoffInstrProf;
25480093f4SDimitry Andric extern cl::opt<int> PgsoCutoffSampleProf;
26480093f4SDimitry Andric
shouldOptimizeForSize(const MachineFunction * MF,ProfileSummaryInfo * PSI,const MachineBlockFrequencyInfo * MBFI,PGSOQueryType QueryType)27480093f4SDimitry Andric bool llvm::shouldOptimizeForSize(const MachineFunction *MF,
28480093f4SDimitry Andric ProfileSummaryInfo *PSI,
29480093f4SDimitry Andric const MachineBlockFrequencyInfo *MBFI,
30480093f4SDimitry Andric PGSOQueryType QueryType) {
31*06c3fb27SDimitry Andric return shouldFuncOptimizeForSizeImpl(MF, PSI, MBFI, QueryType);
32480093f4SDimitry Andric }
33480093f4SDimitry Andric
shouldOptimizeForSize(const MachineBasicBlock * MBB,ProfileSummaryInfo * PSI,const MachineBlockFrequencyInfo * MBFI,PGSOQueryType QueryType)34480093f4SDimitry Andric bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,
35480093f4SDimitry Andric ProfileSummaryInfo *PSI,
36480093f4SDimitry Andric const MachineBlockFrequencyInfo *MBFI,
37480093f4SDimitry Andric PGSOQueryType QueryType) {
385ffd83dbSDimitry Andric assert(MBB);
39*06c3fb27SDimitry Andric return shouldOptimizeForSizeImpl(MBB, PSI, MBFI, QueryType);
40480093f4SDimitry Andric }
415ffd83dbSDimitry Andric
shouldOptimizeForSize(const MachineBasicBlock * MBB,ProfileSummaryInfo * PSI,MBFIWrapper * MBFIW,PGSOQueryType QueryType)425ffd83dbSDimitry Andric bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,
435ffd83dbSDimitry Andric ProfileSummaryInfo *PSI,
445ffd83dbSDimitry Andric MBFIWrapper *MBFIW,
455ffd83dbSDimitry Andric PGSOQueryType QueryType) {
465ffd83dbSDimitry Andric assert(MBB);
475ffd83dbSDimitry Andric if (!PSI || !MBFIW)
485ffd83dbSDimitry Andric return false;
495ffd83dbSDimitry Andric BlockFrequency BlockFreq = MBFIW->getBlockFreq(MBB);
50*06c3fb27SDimitry Andric return shouldOptimizeForSizeImpl(BlockFreq, PSI, &MBFIW->getMBFI(),
51*06c3fb27SDimitry Andric QueryType);
525ffd83dbSDimitry Andric }
53