1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[PGO][PGSO] Distinguish queries from unit tests and explicitly enable for the existing IR passes only. NFC.

Summary:
This is one more prep step necessary before the code gen pass instrumentation
code could go in.

Reviewers: davidxl

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70988
This commit is contained in:
Hiroshi Yamauchi 2019-12-03 15:02:37 -08:00
parent 33ec300192
commit 60e56af075
4 changed files with 33 additions and 16 deletions

View File

@ -21,6 +21,7 @@ using namespace llvm;
extern cl::opt<bool> EnablePGSO;
extern cl::opt<bool> PGSOLargeWorkingSetSizeOnly;
extern cl::opt<bool> PGSOIRPassOrTestOnly;
extern cl::opt<bool> PGSOColdCodeOnly;
extern cl::opt<bool> ForcePGSO;
extern cl::opt<int> PgsoCutoffInstrProf;
@ -34,8 +35,9 @@ class Function;
class ProfileSummaryInfo;
enum class PGSOQueryType {
IRPass, // A query call from an IR-level transform pass.
Other, // Others.
IRPass, // A query call from an IR-level transform pass.
Test, // A query call from a unit test.
Other, // Others.
};
template<typename AdapterT, typename FuncT, typename BFIT>
@ -48,6 +50,11 @@ bool shouldFuncOptimizeForSizeImpl(const FuncT *F, ProfileSummaryInfo *PSI,
return true;
if (!EnablePGSO)
return false;
// Temporarily enable size optimizations only for the IR pass or test query
// sites for gradual commit/rollout. This is to be removed later.
if (PGSOIRPassOrTestOnly && !(QueryType == PGSOQueryType::IRPass ||
QueryType == PGSOQueryType::Test))
return false;
if (PGSOColdCodeOnly ||
(PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize())) {
// Even if the working set size isn't large, size-optimize cold code.
@ -68,6 +75,11 @@ bool shouldOptimizeForSizeImpl(const BlockT *BB, ProfileSummaryInfo *PSI,
return true;
if (!EnablePGSO)
return false;
// Temporarily enable size optimizations only for the IR pass or test query
// sites for gradual commit/rollout. This is to be removed later.
if (PGSOIRPassOrTestOnly && !(QueryType == PGSOQueryType::IRPass ||
QueryType == PGSOQueryType::Test))
return false;
if (PGSOColdCodeOnly ||
(PGSOLargeWorkingSetSizeOnly && !PSI->hasLargeWorkingSetSize())) {
// Even if the working set size isn't large, size-optimize cold code.

View File

@ -28,6 +28,11 @@ cl::opt<bool> PGSOColdCodeOnly(
cl::desc("Apply the profile guided size optimizations only "
"to cold code."));
cl::opt<bool> PGSOIRPassOrTestOnly(
"pgso-ir-pass-or-test-only", cl::Hidden, cl::init(true),
cl::desc("Apply the profile guided size optimizations only"
"to the IR passes or tests."));
cl::opt<bool> ForcePGSO(
"force-pgso", cl::Hidden, cl::init(false),
cl::desc("Force the (profiled-guided) size optimizations. "));

View File

@ -113,13 +113,13 @@ TEST_F(MachineSizeOptsTest, Test) {
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));
EXPECT_FALSE(shouldOptimizeForSize(F, &PSI, MBFI_F, PGSOQueryType::Test));
EXPECT_TRUE(shouldOptimizeForSize(G, &PSI, MBFI_G, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(H, &PSI, MBFI_H, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(&BB0, &PSI, MBFI_F, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(BB1, &PSI, MBFI_F, PGSOQueryType::Test));
EXPECT_TRUE(shouldOptimizeForSize(BB2, &PSI, MBFI_F, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(BB3, &PSI, MBFI_F, PGSOQueryType::Test));
}
const char* MachineSizeOptsTest::MIRString = R"MIR(

View File

@ -68,13 +68,13 @@ TEST_F(SizeOptsTest, Test) {
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));
EXPECT_FALSE(shouldOptimizeForSize(F, &PSI, BFI_F, PGSOQueryType::Test));
EXPECT_TRUE(shouldOptimizeForSize(G, &PSI, BFI_G, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(H, &PSI, BFI_H, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(&BB0, &PSI, BFI_F, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(BB1, &PSI, BFI_F, PGSOQueryType::Test));
EXPECT_TRUE(shouldOptimizeForSize(BB2, &PSI, BFI_F, PGSOQueryType::Test));
EXPECT_FALSE(shouldOptimizeForSize(BB3, &PSI, BFI_F, PGSOQueryType::Test));
}
const char* SizeOptsTest::IRString = R"IR(