Commit 8cdfdfee authored by Hiroshi Yamauchi's avatar Hiroshi Yamauchi
Browse files

[PGO][PGSO] Add an optional query type parameter to shouldOptimizeForSize.

Summary:
In case of a need to distinguish different query sites for gradual commit or
debugging of PGSO. NFC.

Reviewers: davidxl

Subscribers: hiraditya, zzheng, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70510
parent 7999cd41
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -23,14 +23,16 @@ class MachineBlockFrequencyInfo;
class MachineFunction;

/// Returns true if machine function \p MF is suggested to be size-optimized
/// base on the profile.
/// based on the profile.
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI,
                           const MachineBlockFrequencyInfo *BFI);
                           const MachineBlockFrequencyInfo *BFI,
                           PGSOQueryType QueryType = PGSOQueryType::Other);
/// Returns true if machine basic block \p MBB is suggested to be size-optimized
/// base on the profile.
/// based on the profile.
bool shouldOptimizeForSize(const MachineBasicBlock *MBB,
                           ProfileSummaryInfo *PSI,
                           const MachineBlockFrequencyInfo *MBFI);
                           const MachineBlockFrequencyInfo *MBFI,
                           PGSOQueryType QueryType = PGSOQueryType::Other);

} // end namespace llvm

+14 −7
Original line number Diff line number Diff line
@@ -33,9 +33,14 @@ class BlockFrequencyInfo;
class Function;
class ProfileSummaryInfo;

enum class PGSOQueryType {
  IRPass,  // A query call from an IR-level transform pass.
  Other,   // Others.
};

template<typename AdapterT, typename FuncT, typename BFIT>
bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI,
                                   BFIT *BFI) {
                                   BFIT *BFI, PGSOQueryType QueryType) {
  assert(F);
  if (!PSI || !BFI || !PSI->hasProfileSummary())
    return false;
@@ -55,7 +60,7 @@ bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI,

template<typename AdapterT, typename BlockT, typename BFIT>
bool shouldOptimizeForSizeImpl(const BlockT *BB, ProfileSummaryInfo *PSI,
                               BFIT *BFI) {
                               BFIT *BFI, PGSOQueryType QueryType) {
  assert(BB);
  if (!PSI || !BFI || !PSI->hasProfileSummary())
    return false;
@@ -73,15 +78,17 @@ bool shouldOptimizeForSizeImpl(const BlockT *BB, ProfileSummaryInfo *PSI,
      BB, PSI, BFI);
}

/// Returns true if function \p F is suggested to be size-optimized base on the
/// Returns true if function \p F is suggested to be size-optimized based on the
/// profile.
bool shouldOptimizeForSize(const Function *F, ProfileSummaryInfo *PSI,
                           BlockFrequencyInfo *BFI);
                           BlockFrequencyInfo *BFI,
                           PGSOQueryType QueryType = PGSOQueryType::Other);

/// Returns true if basic block \p BB is suggested to be size-optimized base
/// on the profile.
/// Returns true if basic block \p BB is suggested to be size-optimized based on
/// the profile.
bool shouldOptimizeForSize(const BasicBlock *BB, ProfileSummaryInfo *PSI,
                           BlockFrequencyInfo *BFI);
                           BlockFrequencyInfo *BFI,
                           PGSOQueryType QueryType = PGSOQueryType::Other);

} // end namespace llvm

+6 −4
Original line number Diff line number Diff line
@@ -107,14 +107,16 @@ struct MachineBasicBlockBFIAdapter {

bool llvm::shouldOptimizeForSize(const MachineFunction *MF,
                                 ProfileSummaryInfo *PSI,
                                 const MachineBlockFrequencyInfo *MBFI) {
                                 const MachineBlockFrequencyInfo *MBFI,
                                 PGSOQueryType QueryType) {
  return shouldFuncOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>(
      MF, PSI, MBFI);
      MF, PSI, MBFI, QueryType);
}

bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB,
                                 ProfileSummaryInfo *PSI,
                                 const MachineBlockFrequencyInfo *MBFI) {
                                 const MachineBlockFrequencyInfo *MBFI,
                                 PGSOQueryType QueryType) {
  return shouldOptimizeForSizeImpl<MachineBasicBlockBFIAdapter>(
      MBB, PSI, MBFI);
      MBB, PSI, MBFI, QueryType);
}
+2 −1
Original line number Diff line number Diff line
@@ -553,7 +553,8 @@ ConstantHoistingPass::maximizeConstantsInRange(ConstCandVecType::iterator S,
  unsigned NumUses = 0;

  bool OptForSize = Entry->getParent()->hasOptSize() ||
                    llvm::shouldOptimizeForSize(Entry->getParent(), PSI, BFI);
                    llvm::shouldOptimizeForSize(Entry->getParent(), PSI, BFI,
                                                PGSOQueryType::IRPass);
  if (!OptForSize || std::distance(S,E) > 100) {
    for (auto ConstCand = S; ConstCand != E; ++ConstCand) {
      NumUses += ConstCand->Uses.size();
+2 −1
Original line number Diff line number Diff line
@@ -545,7 +545,8 @@ public:
      auto *HeaderBB = L->getHeader();
      auto *F = HeaderBB->getParent();
      bool OptForSize = F->hasOptSize() ||
                        llvm::shouldOptimizeForSize(HeaderBB, PSI, BFI);
                        llvm::shouldOptimizeForSize(HeaderBB, PSI, BFI,
                                                    PGSOQueryType::IRPass);
      if (OptForSize) {
        LLVM_DEBUG(
            dbgs() << "Versioning is needed but not allowed when optimizing "
Loading