From eec7ef7443ddbd32d9328160c31a628642198dc8 Mon Sep 17 00:00:00 2001 From: Vladimir Vereschaka Date: Sun, 20 Oct 2019 20:39:33 +0000 Subject: [PATCH] Reverted r375254 as it has broken some build bots for a long time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375375 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/CodeGen/MachineBlockFrequencyInfo.h | 3 - include/llvm/CodeGen/MachineDominators.h | 5 - include/llvm/CodeGen/MachineLoopInfo.h | 6 - include/llvm/CodeGen/MachineSizeOpts.h | 37 --- include/llvm/Transforms/Utils/SizeOpts.h | 55 +--- lib/CodeGen/CMakeLists.txt | 1 - lib/CodeGen/MachineBlockFrequencyInfo.cpp | 7 - lib/CodeGen/MachineDominators.cpp | 6 +- lib/CodeGen/MachineLoopInfo.cpp | 8 +- lib/CodeGen/MachineSizeOpts.cpp | 120 --------- lib/Transforms/Utils/SizeOpts.cpp | 68 ++--- unittests/CodeGen/CMakeLists.txt | 1 - unittests/CodeGen/MachineSizeOptsTest.cpp | 234 ------------------ unittests/Transforms/Utils/CMakeLists.txt | 1 - unittests/Transforms/Utils/SizeOptsTest.cpp | 129 ---------- 15 files changed, 20 insertions(+), 661 deletions(-) delete mode 100644 include/llvm/CodeGen/MachineSizeOpts.h delete mode 100644 lib/CodeGen/MachineSizeOpts.cpp delete mode 100644 unittests/CodeGen/MachineSizeOptsTest.cpp delete mode 100644 unittests/Transforms/Utils/SizeOptsTest.cpp diff --git a/include/llvm/CodeGen/MachineBlockFrequencyInfo.h b/include/llvm/CodeGen/MachineBlockFrequencyInfo.h index 2a826d0b64c..a438ecfcc25 100644 --- a/include/llvm/CodeGen/MachineBlockFrequencyInfo.h +++ b/include/llvm/CodeGen/MachineBlockFrequencyInfo.h @@ -38,9 +38,6 @@ public: static char ID; MachineBlockFrequencyInfo(); - explicit MachineBlockFrequencyInfo(MachineFunction &F, - MachineBranchProbabilityInfo &MBPI, - MachineLoopInfo &MLI); ~MachineBlockFrequencyInfo() override; void getAnalysisUsage(AnalysisUsage &AU) const override; diff --git a/include/llvm/CodeGen/MachineDominators.h b/include/llvm/CodeGen/MachineDominators.h index 9d31232c9b9..e4d7a02f8c4 100644 --- a/include/llvm/CodeGen/MachineDominators.h +++ b/include/llvm/CodeGen/MachineDominators.h @@ -81,9 +81,6 @@ public: static char ID; // Pass ID, replacement for typeid MachineDominatorTree(); - explicit MachineDominatorTree(MachineFunction &MF) : MachineFunctionPass(ID) { - calculate(MF); - } DomTreeT &getBase() { if (!DT) DT.reset(new DomTreeT()); @@ -114,8 +111,6 @@ public: bool runOnMachineFunction(MachineFunction &F) override; - void calculate(MachineFunction &F); - bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const { applySplitCriticalEdges(); diff --git a/include/llvm/CodeGen/MachineLoopInfo.h b/include/llvm/CodeGen/MachineLoopInfo.h index 1612c8b86a3..da6df59c739 100644 --- a/include/llvm/CodeGen/MachineLoopInfo.h +++ b/include/llvm/CodeGen/MachineLoopInfo.h @@ -37,7 +37,6 @@ namespace llvm { -class MachineDominatorTree; // Implementation in LoopInfoImpl.h class MachineLoop; extern template class LoopBase; @@ -92,10 +91,6 @@ public: MachineLoopInfo() : MachineFunctionPass(ID) { initializeMachineLoopInfoPass(*PassRegistry::getPassRegistry()); } - explicit MachineLoopInfo(MachineDominatorTree &MDT) - : MachineFunctionPass(ID) { - calculate(MDT); - } MachineLoopInfo(const MachineLoopInfo &) = delete; MachineLoopInfo &operator=(const MachineLoopInfo &) = delete; @@ -138,7 +133,6 @@ public: /// Calculate the natural loop information. bool runOnMachineFunction(MachineFunction &F) override; - void calculate(MachineDominatorTree &MDT); void releaseMemory() override { LI.releaseMemory(); } diff --git a/include/llvm/CodeGen/MachineSizeOpts.h b/include/llvm/CodeGen/MachineSizeOpts.h deleted file mode 100644 index 75e871d9747..00000000000 --- a/include/llvm/CodeGen/MachineSizeOpts.h +++ /dev/null @@ -1,37 +0,0 @@ -//===- MachineSizeOpts.h - machine size optimization ------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file contains some shared machine IR code size optimization related -// code. -// -//===----------------------------------------------------------------------===// -#ifndef LLVM_CODEGEN_MACHINE_SIZEOPTS_H -#define LLVM_CODEGEN_MACHINE_SIZEOPTS_H - -#include "llvm/Transforms/Utils/SizeOpts.h" - -namespace llvm { - -class ProfileSummaryInfo; -class MachineBasicBlock; -class MachineBlockFrequencyInfo; -class MachineFunction; - -/// Returns true if machine function \p MF is suggested to be size-optimized -/// base on the profile. -bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *BFI); -/// Returns true if machine basic block \p MBB is suggested to be size-optimized -/// base on the profile. -bool shouldOptimizeForSize(const MachineBasicBlock *MBB, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI); - -} // end namespace llvm - -#endif // LLVM_CODEGEN_MACHINE_SIZEOPTS_H diff --git a/include/llvm/Transforms/Utils/SizeOpts.h b/include/llvm/Transforms/Utils/SizeOpts.h index 1c56da08ef8..1a052c694e6 100644 --- a/include/llvm/Transforms/Utils/SizeOpts.h +++ b/include/llvm/Transforms/Utils/SizeOpts.h @@ -13,18 +13,6 @@ #ifndef LLVM_TRANSFORMS_UTILS_SIZEOPTS_H #define LLVM_TRANSFORMS_UTILS_SIZEOPTS_H -#include "llvm/Analysis/BlockFrequencyInfo.h" -#include "llvm/Analysis/ProfileSummaryInfo.h" -#include "llvm/Support/CommandLine.h" - -using namespace llvm; - -extern cl::opt EnablePGSO; -extern cl::opt PGSOLargeWorkingSetSizeOnly; -extern cl::opt ForcePGSO; -extern cl::opt PgsoCutoffInstrProf; -extern cl::opt PgsoCutoffSampleProf; - namespace llvm { class BasicBlock; @@ -32,52 +20,13 @@ class BlockFrequencyInfo; class Function; class ProfileSummaryInfo; -template -bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI, - BFIT *BFI) { - assert(F); - if (!PSI || !BFI || !PSI->hasProfileSummary()) - return false; - if (ForcePGSO) - return true; - if (!EnablePGSO) - return false; - if (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize()) { - // Even if the working set size isn't large, size-optimize cold code. - return AdapterT::isFunctionColdInCallGraph(F, PSI, *BFI); - } - return !AdapterT::isFunctionHotInCallGraphNthPercentile( - PSI->hasSampleProfile() ? PgsoCutoffSampleProf : PgsoCutoffInstrProf, - F, PSI, *BFI); -} - -template -bool shouldOptimizeForSizeImpl(const BlockT *BB, ProfileSummaryInfo *PSI, - BFIT *BFI) { - assert(BB); - if (!PSI || !BFI || !PSI->hasProfileSummary()) - return false; - if (ForcePGSO) - return true; - if (!EnablePGSO) - return false; - if (PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize()) { - // Even if the working set size isn't large, size-optimize cold code. - return AdapterT::isColdBlock(BB, PSI, BFI); - } - return !AdapterT::isHotBlockNthPercentile( - PSI->hasSampleProfile() ? PgsoCutoffSampleProf : PgsoCutoffInstrProf, - BB, PSI, BFI); -} - /// Returns true if function \p F is suggested to be size-optimized base on the /// profile. -bool shouldOptimizeForSize(const Function *F, ProfileSummaryInfo *PSI, +bool shouldOptimizeForSize(Function *F, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI); - /// Returns true if basic block \p BB is suggested to be size-optimized base /// on the profile. -bool shouldOptimizeForSize(const BasicBlock *BB, ProfileSummaryInfo *PSI, +bool shouldOptimizeForSize(BasicBlock *BB, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI); } // end namespace llvm diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt index f5c18f89fa0..50b469d6d93 100644 --- a/lib/CodeGen/CMakeLists.txt +++ b/lib/CodeGen/CMakeLists.txt @@ -92,7 +92,6 @@ add_llvm_library(LLVMCodeGen MachineRegisterInfo.cpp MachineScheduler.cpp MachineSink.cpp - MachineSizeOpts.cpp MachineSSAUpdater.cpp MachineTraceMetrics.cpp MachineVerifier.cpp diff --git a/lib/CodeGen/MachineBlockFrequencyInfo.cpp b/lib/CodeGen/MachineBlockFrequencyInfo.cpp index 889fde606a4..53a35b7e89c 100644 --- a/lib/CodeGen/MachineBlockFrequencyInfo.cpp +++ b/lib/CodeGen/MachineBlockFrequencyInfo.cpp @@ -172,13 +172,6 @@ MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry()); } -MachineBlockFrequencyInfo::MachineBlockFrequencyInfo( - MachineFunction &F, - MachineBranchProbabilityInfo &MBPI, - MachineLoopInfo &MLI) : MachineFunctionPass(ID) { - calculate(F, MBPI, MLI); -} - MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() = default; void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const { diff --git a/lib/CodeGen/MachineDominators.cpp b/lib/CodeGen/MachineDominators.cpp index 0d57bca37d9..706c706d752 100644 --- a/lib/CodeGen/MachineDominators.cpp +++ b/lib/CodeGen/MachineDominators.cpp @@ -49,15 +49,11 @@ void MachineDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const { } bool MachineDominatorTree::runOnMachineFunction(MachineFunction &F) { - calculate(F); - return false; -} - -void MachineDominatorTree::calculate(MachineFunction &F) { CriticalEdgesToSplit.clear(); NewBBs.clear(); DT.reset(new DomTreeBase()); DT->recalculate(F); + return false; } MachineDominatorTree::MachineDominatorTree() diff --git a/lib/CodeGen/MachineLoopInfo.cpp b/lib/CodeGen/MachineLoopInfo.cpp index 85822a67149..3b8b430d1b0 100644 --- a/lib/CodeGen/MachineLoopInfo.cpp +++ b/lib/CodeGen/MachineLoopInfo.cpp @@ -36,13 +36,9 @@ INITIALIZE_PASS_END(MachineLoopInfo, "machine-loops", char &llvm::MachineLoopInfoID = MachineLoopInfo::ID; bool MachineLoopInfo::runOnMachineFunction(MachineFunction &) { - calculate(getAnalysis()); - return false; -} - -void MachineLoopInfo::calculate(MachineDominatorTree &MDT) { releaseMemory(); - LI.analyze(MDT.getBase()); + LI.analyze(getAnalysis().getBase()); + return false; } void MachineLoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { diff --git a/lib/CodeGen/MachineSizeOpts.cpp b/lib/CodeGen/MachineSizeOpts.cpp deleted file mode 100644 index 0c2ef3321e0..00000000000 --- a/lib/CodeGen/MachineSizeOpts.cpp +++ /dev/null @@ -1,120 +0,0 @@ -//===- MachineSizeOpts.cpp - code size optimization related code ----------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file contains some shared machine IR code size optimization related -// code. -// -//===----------------------------------------------------------------------===// - -#include "llvm/CodeGen/MachineSizeOpts.h" -#include "llvm/Analysis/ProfileSummaryInfo.h" -#include "llvm/CodeGen/MachineBlockFrequencyInfo.h" - -using namespace llvm; - -extern cl::opt EnablePGSO; -extern cl::opt PGSOLargeWorkingSetSizeOnly; -extern cl::opt ForcePGSO; -extern cl::opt PgsoCutoffInstrProf; -extern cl::opt PgsoCutoffSampleProf; - -namespace machine_size_opts_detail { - -/// Like ProfileSummaryInfo::isColdBlock but for MachineBasicBlock. -bool isColdBlock(const MachineBasicBlock *MBB, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI) { - auto Count = MBFI->getBlockProfileCount(MBB); - return Count && PSI->isColdCount(*Count); -} - -/// Like ProfileSummaryInfo::isHotBlockNthPercentile but for MachineBasicBlock. -static bool isHotBlockNthPercentile(int PercentileCutoff, - const MachineBasicBlock *MBB, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI) { - auto Count = MBFI->getBlockProfileCount(MBB); - return Count && PSI->isHotCountNthPercentile(PercentileCutoff, *Count); -} - -/// Like ProfileSummaryInfo::isFunctionColdInCallGraph but for -/// MachineFunction. -bool isFunctionColdInCallGraph( - const MachineFunction *MF, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo &MBFI) { - if (auto FunctionCount = MF->getFunction().getEntryCount()) - if (!PSI->isColdCount(FunctionCount.getCount())) - return false; - for (const auto &MBB : *MF) - if (!isColdBlock(&MBB, PSI, &MBFI)) - return false; - return true; -} - -/// Like ProfileSummaryInfo::isFunctionHotInCallGraphNthPercentile but for -/// MachineFunction. -bool isFunctionHotInCallGraphNthPercentile( - int PercentileCutoff, - const MachineFunction *MF, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo &MBFI) { - if (auto FunctionCount = MF->getFunction().getEntryCount()) - if (PSI->isHotCountNthPercentile(PercentileCutoff, - FunctionCount.getCount())) - return true; - for (const auto &MBB : *MF) - if (isHotBlockNthPercentile(PercentileCutoff, &MBB, PSI, &MBFI)) - return true; - return false; -} -} // namespace machine_size_opts_detail - -namespace { -struct MachineBasicBlockBFIAdapter { - static bool isFunctionColdInCallGraph(const MachineFunction *MF, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo &MBFI) { - return machine_size_opts_detail::isFunctionColdInCallGraph(MF, PSI, MBFI); - } - static bool isFunctionHotInCallGraphNthPercentile( - int CutOff, - const MachineFunction *MF, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo &MBFI) { - return machine_size_opts_detail::isFunctionHotInCallGraphNthPercentile( - CutOff, MF, PSI, MBFI); - } - static bool isColdBlock(const MachineBasicBlock *MBB, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI) { - return machine_size_opts_detail::isColdBlock(MBB, PSI, MBFI); - } - static bool isHotBlockNthPercentile(int CutOff, - const MachineBasicBlock *MBB, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI) { - return machine_size_opts_detail::isHotBlockNthPercentile( - CutOff, MBB, PSI, MBFI); - } -}; -} // end anonymous namespace - -bool llvm::shouldOptimizeForSize(const MachineFunction *MF, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI) { - return shouldFuncOptimizeForSizeImpl( - MF, PSI, MBFI); -} - -bool llvm::shouldOptimizeForSize(const MachineBasicBlock *MBB, - ProfileSummaryInfo *PSI, - const MachineBlockFrequencyInfo *MBFI) { - return shouldOptimizeForSizeImpl( - MBB, PSI, MBFI); -} diff --git a/lib/Transforms/Utils/SizeOpts.cpp b/lib/Transforms/Utils/SizeOpts.cpp index f819c67d69d..1519751197d 100644 --- a/lib/Transforms/Utils/SizeOpts.cpp +++ b/lib/Transforms/Utils/SizeOpts.cpp @@ -10,66 +10,28 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/BlockFrequencyInfo.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Transforms/Utils/SizeOpts.h" - using namespace llvm; -cl::opt EnablePGSO( +static cl::opt ProfileGuidedSizeOpt( "pgso", cl::Hidden, cl::init(true), - cl::desc("Enable the profile guided size optimizations. ")); - -cl::opt PGSOLargeWorkingSetSizeOnly( - "pgso-lwss-only", cl::Hidden, cl::init(true), - cl::desc("Apply the profile guided size optimizations only " - "if the working set size is large (except for cold code.)")); - -cl::opt ForcePGSO( - "force-pgso", cl::Hidden, cl::init(false), - cl::desc("Force the (profiled-guided) size optimizations. ")); - -cl::opt PgsoCutoffInstrProf( - "pgso-cutoff-instr-prof", cl::Hidden, cl::init(250000), cl::ZeroOrMore, - cl::desc("The profile guided size optimization profile summary cutoff " - "for instrumentation profile.")); - -cl::opt PgsoCutoffSampleProf( - "pgso-cutoff-sample-prof", cl::Hidden, cl::init(800000), cl::ZeroOrMore, - cl::desc("The profile guided size optimization profile summary cutoff " - "for sample profile.")); - -namespace { -struct BasicBlockBFIAdapter { - static bool isFunctionColdInCallGraph(const Function *F, - ProfileSummaryInfo *PSI, - BlockFrequencyInfo &BFI) { - return PSI->isFunctionColdInCallGraph(F, BFI); - } - static bool isFunctionHotInCallGraphNthPercentile(int CutOff, - const Function *F, - ProfileSummaryInfo *PSI, - BlockFrequencyInfo &BFI) { - return PSI->isFunctionHotInCallGraphNthPercentile(CutOff, F, BFI); - } - static bool isColdBlock(const BasicBlock *BB, - ProfileSummaryInfo *PSI, - BlockFrequencyInfo *BFI) { - return PSI->isColdBlock(BB, BFI); - } - static bool isHotBlockNthPercentile(int CutOff, - const BasicBlock *BB, - ProfileSummaryInfo *PSI, - BlockFrequencyInfo *BFI) { - return PSI->isHotBlockNthPercentile(CutOff, BB, BFI); - } -}; -} // end anonymous namespace + cl::desc("Enable the profile guided size optimization. ")); -bool llvm::shouldOptimizeForSize(const Function *F, ProfileSummaryInfo *PSI, +bool llvm::shouldOptimizeForSize(Function *F, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) { - return shouldFuncOptimizeForSizeImpl(F, PSI, BFI); + assert(F); + if (!PSI || !BFI || !PSI->hasProfileSummary()) + return false; + return ProfileGuidedSizeOpt && PSI->isFunctionColdInCallGraph(F, *BFI); } -bool llvm::shouldOptimizeForSize(const BasicBlock *BB, ProfileSummaryInfo *PSI, +bool llvm::shouldOptimizeForSize(BasicBlock *BB, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) { - return shouldOptimizeForSizeImpl(BB, PSI, BFI); + assert(BB); + if (!PSI || !BFI || !PSI->hasProfileSummary()) + return false; + return ProfileGuidedSizeOpt && PSI->isColdBlock(BB, BFI); } diff --git a/unittests/CodeGen/CMakeLists.txt b/unittests/CodeGen/CMakeLists.txt index 95cbafbe611..fc8cd22bcc7 100644 --- a/unittests/CodeGen/CMakeLists.txt +++ b/unittests/CodeGen/CMakeLists.txt @@ -19,7 +19,6 @@ add_llvm_unittest(CodeGenTests MachineInstrBundleIteratorTest.cpp MachineInstrTest.cpp MachineOperandTest.cpp - MachineSizeOptsTest.cpp ScalableVectorMVTsTest.cpp TypeTraitsTest.cpp TargetOptionsTest.cpp diff --git a/unittests/CodeGen/MachineSizeOptsTest.cpp b/unittests/CodeGen/MachineSizeOptsTest.cpp deleted file mode 100644 index f8b0c23e971..00000000000 --- a/unittests/CodeGen/MachineSizeOptsTest.cpp +++ /dev/null @@ -1,234 +0,0 @@ -//===- MachineSizeOptsTest.cpp --------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/CodeGen/MachineSizeOpts.h" -#include "llvm/Analysis/ProfileSummaryInfo.h" -#include "llvm/Analysis/BlockFrequencyInfo.h" -#include "llvm/Analysis/BranchProbabilityInfo.h" -#include "llvm/Analysis/LoopInfo.h" -#include "llvm/CodeGen/MIRParser/MIRParser.h" -#include "llvm/CodeGen/MachineBlockFrequencyInfo.h" -#include "llvm/CodeGen/MachineBranchProbabilityInfo.h" -#include "llvm/CodeGen/MachineDominators.h" -#include "llvm/CodeGen/MachineLoopInfo.h" -#include "llvm/CodeGen/MachineModuleInfo.h" -#include "llvm/Support/TargetRegistry.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Target/TargetMachine.h" -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -std::unique_ptr createTargetMachine() { - auto TT(Triple::normalize("x86_64--")); - std::string Error; - const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error); - return std::unique_ptr(static_cast( - TheTarget->createTargetMachine(TT, "", "", TargetOptions(), None, None, - CodeGenOpt::Default))); -} - -class MachineSizeOptsTest : public testing::Test { - protected: - static const char* MIRString; - LLVMContext Context; - std::unique_ptr TM; - std::unique_ptr MMI; - std::unique_ptr Parser; - std::unique_ptr M; - struct BFIData { - std::unique_ptr MDT; - std::unique_ptr MLI; - std::unique_ptr MBPI; - std::unique_ptr MBFI; - BFIData(MachineFunction &MF) { - MDT.reset(new MachineDominatorTree(MF)); - MLI.reset(new MachineLoopInfo(*MDT)); - MBPI.reset(new MachineBranchProbabilityInfo()); - MBFI.reset(new MachineBlockFrequencyInfo(MF, *MBPI, *MLI)); - } - MachineBlockFrequencyInfo *get() { return MBFI.get(); } - }; - - static void SetUpTestCase() { - InitializeAllTargets(); - InitializeAllTargetMCs(); - } - - void SetUp() override { - TM = createTargetMachine(); - std::unique_ptr MBuffer = - MemoryBuffer::getMemBuffer(MIRString); - Parser = createMIRParser(std::move(MBuffer), Context); - if (!Parser) - report_fatal_error("null MIRParser"); - M = Parser->parseIRModule(); - if (!M) - report_fatal_error("parseIRModule failed"); - M->setTargetTriple(TM->getTargetTriple().getTriple()); - M->setDataLayout(TM->createDataLayout()); - MMI = std::make_unique(TM.get()); - if (Parser->parseMachineFunctions(*M, *MMI.get())) - report_fatal_error("parseMachineFunctions failed"); - } - - MachineFunction *getMachineFunction(Module *M, StringRef Name) { - auto F = M->getFunction(Name); - if (!F) - report_fatal_error("null Function"); - auto &MF = MMI->getOrCreateMachineFunction(*F); - return &MF; - } -}; - -TEST_F(MachineSizeOptsTest, Test) { - MachineFunction *F = getMachineFunction(M.get(), "f"); - ASSERT_TRUE(F != nullptr); - MachineFunction *G = getMachineFunction(M.get(), "g"); - ASSERT_TRUE(G != nullptr); - MachineFunction *H = getMachineFunction(M.get(), "h"); - ASSERT_TRUE(H != nullptr); - ProfileSummaryInfo PSI = ProfileSummaryInfo(*M.get()); - ASSERT_TRUE(PSI.hasProfileSummary()); - BFIData BFID_F(*F); - BFIData BFID_G(*G); - BFIData BFID_H(*H); - MachineBlockFrequencyInfo *MBFI_F = BFID_F.get(); - MachineBlockFrequencyInfo *MBFI_G = BFID_G.get(); - MachineBlockFrequencyInfo *MBFI_H = BFID_H.get(); - MachineBasicBlock &BB0 = F->front(); - auto iter = BB0.succ_begin(); - MachineBasicBlock *BB1 = *iter; - iter++; - MachineBasicBlock *BB2 = *iter; - iter++; - ASSERT_TRUE(iter == BB0.succ_end()); - MachineBasicBlock *BB3 = *BB1->succ_begin(); - ASSERT_TRUE(BB3 == *BB2->succ_begin()); - EXPECT_FALSE(shouldOptimizeForSize(F, &PSI, MBFI_F)); - EXPECT_TRUE(shouldOptimizeForSize(G, &PSI, MBFI_G)); - EXPECT_FALSE(shouldOptimizeForSize(H, &PSI, MBFI_H)); - EXPECT_FALSE(shouldOptimizeForSize(&BB0, &PSI, MBFI_F)); - EXPECT_FALSE(shouldOptimizeForSize(BB1, &PSI, MBFI_F)); - EXPECT_TRUE(shouldOptimizeForSize(BB2, &PSI, MBFI_F)); - EXPECT_FALSE(shouldOptimizeForSize(BB3, &PSI, MBFI_F)); -} - -const char* MachineSizeOptsTest::MIRString = R"MIR( ---- | - define i32 @g(i32 %x) !prof !14 { - ret i32 0 - } - - define i32 @h(i32 %x) !prof !15 { - ret i32 0 - } - - define i32 @f(i32 %x) !prof !16 { - bb0: - %y1 = icmp eq i32 %x, 0 - br i1 %y1, label %bb1, label %bb2, !prof !17 - - bb1: ; preds = %bb0 - %z1 = call i32 @g(i32 %x) - br label %bb3 - - bb2: ; preds = %bb0 - %z2 = call i32 @h(i32 %x) - br label %bb3 - - bb3: ; preds = %bb2, %bb1 - %y2 = phi i32 [ 0, %bb1 ], [ 1, %bb2 ] - ret i32 %y2 - } - - !llvm.module.flags = !{!0} - - !0 = !{i32 1, !"ProfileSummary", !1} - !1 = !{!2, !3, !4, !5, !6, !7, !8, !9} - !2 = !{!"ProfileFormat", !"InstrProf"} - !3 = !{!"TotalCount", i64 10000} - !4 = !{!"MaxCount", i64 10} - !5 = !{!"MaxInternalCount", i64 1} - !6 = !{!"MaxFunctionCount", i64 1000} - !7 = !{!"NumCounts", i64 3} - !8 = !{!"NumFunctions", i64 3} - !9 = !{!"DetailedSummary", !10} - !10 = !{!11, !12, !13} - !11 = !{i32 10000, i64 1000, i32 1} - !12 = !{i32 999000, i64 300, i32 3} - !13 = !{i32 999999, i64 5, i32 10} - !14 = !{!"function_entry_count", i64 1} - !15 = !{!"function_entry_count", i64 100} - !16 = !{!"function_entry_count", i64 400} - !17 = !{!"branch_weights", i32 100, i32 1} - -... ---- -name: g -body: | - bb.0: - %1:gr32 = MOV32r0 implicit-def dead $eflags - $eax = COPY %1 - RET 0, $eax - -... ---- -name: h -body: | - bb.0: - %1:gr32 = MOV32r0 implicit-def dead $eflags - $eax = COPY %1 - RET 0, $eax - -... ---- -name: f -tracksRegLiveness: true -body: | - bb.0: - successors: %bb.1(0x7ebb907a), %bb.2(0x01446f86) - liveins: $edi - - %1:gr32 = COPY $edi - TEST32rr %1, %1, implicit-def $eflags - JCC_1 %bb.2, 5, implicit $eflags - JMP_1 %bb.1 - - bb.1: - successors: %bb.3(0x80000000) - - ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp - $edi = COPY %1 - CALL64pcrel32 @g, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax - ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp - %5:gr32 = COPY $eax - %4:gr32 = MOV32r0 implicit-def dead $eflags - JMP_1 %bb.3 - - bb.2: - successors: %bb.3(0x80000000) - - ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp - $edi = COPY %1 - CALL64pcrel32 @h, csr_64, implicit $rsp, implicit $ssp, implicit $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax - ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp - %3:gr32 = COPY $eax - %2:gr32 = MOV32ri 1 - - bb.3: - %0:gr32 = PHI %2, %bb.2, %4, %bb.1 - $eax = COPY %0 - RET 0, $eax - -... -)MIR"; - -} // anonymous namespace diff --git a/unittests/Transforms/Utils/CMakeLists.txt b/unittests/Transforms/Utils/CMakeLists.txt index bc993a84f02..785b79865dc 100644 --- a/unittests/Transforms/Utils/CMakeLists.txt +++ b/unittests/Transforms/Utils/CMakeLists.txt @@ -14,7 +14,6 @@ add_llvm_unittest(UtilsTests FunctionComparatorTest.cpp IntegerDivisionTest.cpp LocalTest.cpp - SizeOptsTest.cpp SSAUpdaterBulkTest.cpp UnrollLoopTest.cpp ValueMapperTest.cpp diff --git a/unittests/Transforms/Utils/SizeOptsTest.cpp b/unittests/Transforms/Utils/SizeOptsTest.cpp deleted file mode 100644 index 55ca7863575..00000000000 --- a/unittests/Transforms/Utils/SizeOptsTest.cpp +++ /dev/null @@ -1,129 +0,0 @@ -//===- SizeOptsTest.cpp - SizeOpts unit tests -----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/Transforms/Utils/SizeOpts.h" -#include "llvm/Analysis/ProfileSummaryInfo.h" -#include "llvm/Analysis/BlockFrequencyInfo.h" -#include "llvm/Analysis/BranchProbabilityInfo.h" -#include "llvm/Analysis/LoopInfo.h" -#include "llvm/AsmParser/Parser.h" -#include "llvm/IR/BasicBlock.h" -#include "llvm/IR/Dominators.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Module.h" -#include "llvm/Support/FormatVariadic.h" -#include "llvm/Support/SourceMgr.h" -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -class SizeOptsTest : public testing::Test { -protected: - static const char* IRString; - LLVMContext C; - std::unique_ptr M; - struct BFIData { - std::unique_ptr DT; - std::unique_ptr LI; - std::unique_ptr BPI; - std::unique_ptr BFI; - BFIData(Function &F) { - DT.reset(new DominatorTree(F)); - LI.reset(new LoopInfo(*DT)); - BPI.reset(new BranchProbabilityInfo(F, *LI)); - BFI.reset(new BlockFrequencyInfo(F, *BPI, *LI)); - } - BlockFrequencyInfo *get() { return BFI.get(); } - }; - - void SetUp() override { - SMDiagnostic Err; - M = parseAssemblyString(IRString, Err, C); - } -}; - -TEST_F(SizeOptsTest, Test) { - Function *F = M->getFunction("f"); - Function *G = M->getFunction("g"); - Function *H = M->getFunction("h"); - - ProfileSummaryInfo PSI(*M.get()); - BFIData BFID_F(*F); - BFIData BFID_G(*G); - BFIData BFID_H(*H); - BlockFrequencyInfo *BFI_F = BFID_F.get(); - BlockFrequencyInfo *BFI_G = BFID_G.get(); - BlockFrequencyInfo *BFI_H = BFID_H.get(); - BasicBlock &BB0 = F->getEntryBlock(); - BasicBlock *BB1 = BB0.getTerminator()->getSuccessor(0); - BasicBlock *BB2 = BB0.getTerminator()->getSuccessor(1); - BasicBlock *BB3 = BB1->getSingleSuccessor(); - - EXPECT_TRUE(PSI.hasProfileSummary()); - EXPECT_FALSE(shouldOptimizeForSize(F, &PSI, BFI_F)); - EXPECT_TRUE(shouldOptimizeForSize(G, &PSI, BFI_G)); - EXPECT_FALSE(shouldOptimizeForSize(H, &PSI, BFI_H)); - EXPECT_FALSE(shouldOptimizeForSize(&BB0, &PSI, BFI_F)); - EXPECT_FALSE(shouldOptimizeForSize(BB1, &PSI, BFI_F)); - EXPECT_TRUE(shouldOptimizeForSize(BB2, &PSI, BFI_F)); - EXPECT_FALSE(shouldOptimizeForSize(BB3, &PSI, BFI_F)); -} - -const char* SizeOptsTest::IRString = R"IR( - define i32 @g(i32 %x) !prof !14 { - ret i32 0 - } - - define i32 @h(i32 %x) !prof !15 { - ret i32 0 - } - - define i32 @f(i32 %x) !prof !16 { - bb0: - %y1 = icmp eq i32 %x, 0 - br i1 %y1, label %bb1, label %bb2, !prof !17 - - bb1: ; preds = %bb0 - %z1 = call i32 @g(i32 %x) - br label %bb3 - - bb2: ; preds = %bb0 - %z2 = call i32 @h(i32 %x) - br label %bb3 - - bb3: ; preds = %bb2, %bb1 - %y2 = phi i32 [ 0, %bb1 ], [ 1, %bb2 ] - ret i32 %y2 - } - - !llvm.module.flags = !{!0} - - !0 = !{i32 1, !"ProfileSummary", !1} - !1 = !{!2, !3, !4, !5, !6, !7, !8, !9} - !2 = !{!"ProfileFormat", !"InstrProf"} - !3 = !{!"TotalCount", i64 10000} - !4 = !{!"MaxCount", i64 10} - !5 = !{!"MaxInternalCount", i64 1} - !6 = !{!"MaxFunctionCount", i64 1000} - !7 = !{!"NumCounts", i64 3} - !8 = !{!"NumFunctions", i64 3} - !9 = !{!"DetailedSummary", !10} - !10 = !{!11, !12, !13} - !11 = !{i32 10000, i64 1000, i32 1} - !12 = !{i32 999000, i64 300, i32 3} - !13 = !{i32 999999, i64 5, i32 10} - !14 = !{!"function_entry_count", i64 1} - !15 = !{!"function_entry_count", i64 100} - !16 = !{!"function_entry_count", i64 400} - !17 = !{!"branch_weights", i32 100, i32 1} -)IR"; - -} // end anonymous namespace -- 2.40.0