summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Transforms/Utils/SizeOpts.h16
-rw-r--r--llvm/lib/Transforms/Utils/SizeOpts.cpp5
-rw-r--r--llvm/unittests/Target/X86/MachineSizeOptsTest.cpp14
-rw-r--r--llvm/unittests/Transforms/Utils/SizeOptsTest.cpp14
4 files changed, 33 insertions, 16 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/SizeOpts.h b/llvm/include/llvm/Transforms/Utils/SizeOpts.h
index 2d2edfac8c4..ba0f86c4526 100644
--- a/llvm/include/llvm/Transforms/Utils/SizeOpts.h
+++ b/llvm/include/llvm/Transforms/Utils/SizeOpts.h
@@ -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.
diff --git a/llvm/lib/Transforms/Utils/SizeOpts.cpp b/llvm/lib/Transforms/Utils/SizeOpts.cpp
index 555073af0b2..cab375225e8 100644
--- a/llvm/lib/Transforms/Utils/SizeOpts.cpp
+++ b/llvm/lib/Transforms/Utils/SizeOpts.cpp
@@ -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. "));
diff --git a/llvm/unittests/Target/X86/MachineSizeOptsTest.cpp b/llvm/unittests/Target/X86/MachineSizeOptsTest.cpp
index 2d1ddf11afc..449d426d9b6 100644
--- a/llvm/unittests/Target/X86/MachineSizeOptsTest.cpp
+++ b/llvm/unittests/Target/X86/MachineSizeOptsTest.cpp
@@ -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(
diff --git a/llvm/unittests/Transforms/Utils/SizeOptsTest.cpp b/llvm/unittests/Transforms/Utils/SizeOptsTest.cpp
index 55ca7863575..7caa5ed319a 100644
--- a/llvm/unittests/Transforms/Utils/SizeOptsTest.cpp
+++ b/llvm/unittests/Transforms/Utils/SizeOptsTest.cpp
@@ -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(
OpenPOWER on IntegriCloud