brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 4d458f2 Raw
59 lines · cpp
1//===- MachineSizeOpts.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-exception6//7//===----------------------------------------------------------------------===//8//9// This file contains some shared machine IR code size optimization related10// code.11//12//===----------------------------------------------------------------------===//13 14#include "llvm/CodeGen/MachineSizeOpts.h"15#include "llvm/CodeGen/MBFIWrapper.h"16#include "llvm/Analysis/ProfileSummaryInfo.h"17#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"18 19using namespace llvm;20 21extern cl::opt<bool> EnablePGSO;22extern cl::opt<bool> PGSOLargeWorkingSetSizeOnly;23extern cl::opt<bool> ForcePGSO;24extern cl::opt<int> PgsoCutoffInstrProf;25extern cl::opt<int> PgsoCutoffSampleProf;26 27bool llvm::shouldOptimizeForSize(const MachineFunction *MF,28                                 ProfileSummaryInfo *PSI,29                                 const MachineBlockFrequencyInfo *MBFI,30                                 PGSOQueryType QueryType) {31  if (MF->getFunction().hasOptSize())32    return true;33  return shouldFuncOptimizeForSizeImpl(MF, PSI, MBFI, QueryType);34}35 36bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,37                                 ProfileSummaryInfo *PSI,38                                 const MachineBlockFrequencyInfo *MBFI,39                                 PGSOQueryType QueryType) {40  assert(MBB);41  if (MBB->getParent()->getFunction().hasOptSize())42    return true;43  return shouldOptimizeForSizeImpl(MBB, PSI, MBFI, QueryType);44}45 46bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,47                                 ProfileSummaryInfo *PSI,48                                 MBFIWrapper *MBFIW,49                                 PGSOQueryType QueryType) {50  assert(MBB);51  if (MBB->getParent()->getFunction().hasOptSize())52    return true;53  if (!MBFIW)54    return false;55  BlockFrequency BlockFreq = MBFIW->getBlockFreq(MBB);56  return shouldOptimizeForSizeImpl(BlockFreq, PSI, &MBFIW->getMBFI(),57                                   QueryType);58}59