[llvm] shawbyoung/improving bolt stale matching (PR #93078)
shaw young via llvm-commits
llvm-commits at lists.llvm.org
Wed May 22 10:37:27 PDT 2024
https://github.com/shawbyoung created https://github.com/llvm/llvm-project/pull/93078
Add a NamedRegionTimer to measure the time spent in inferStaleProfile.
>From 30ffe5202bbc2ebbe78518c5d9a8fd00dc03fb6f Mon Sep 17 00:00:00 2001
From: shawy <shawy at meta.com>
Date: Fri, 17 May 2024 16:19:31 -0700
Subject: [PATCH 1/9] [BOLT] Add NamedRegionTimer to inferStaleProfile
Summary: Add a NamedRegionTimer to measure the time spent in inferStaleProfile.
---
bolt/lib/Profile/StaleProfileMatching.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 016962ff34d8d..02b78197e8286 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -31,6 +31,7 @@
#include "llvm/ADT/Hashing.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/xxhash.h"
+#include "llvm/Support/Timer.h"
#include "llvm/Transforms/Utils/SampleProfileInference.h"
#include <queue>
@@ -705,6 +706,10 @@ void assignProfile(BinaryFunction &BF,
bool YAMLProfileReader::inferStaleProfile(
BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
+
+ NamedRegionTimer T( "inferStaleProfile", "inferring from stale profile", "rewrite",
+ "Rewrite passes", opts::InferStaleProfile);
+
if (!BF.hasCFG())
return false;
>From f18d852af7ace3ce1eda1b246aba435bcdde5011 Mon Sep 17 00:00:00 2001
From: shawy <shawy at meta.com>
Date: Mon, 20 May 2024 09:17:26 -0700
Subject: [PATCH 2/9] [BOLT] [NFC] C++ formatting
---
bolt/lib/Profile/StaleProfileMatching.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 02b78197e8286..33182d83449a2 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -30,8 +30,8 @@
#include "llvm/ADT/Bitfields.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/xxhash.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/xxhash.h"
#include "llvm/Transforms/Utils/SampleProfileInference.h"
#include <queue>
@@ -707,8 +707,8 @@ void assignProfile(BinaryFunction &BF,
bool YAMLProfileReader::inferStaleProfile(
BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
- NamedRegionTimer T( "inferStaleProfile", "inferring from stale profile", "rewrite",
- "Rewrite passes", opts::InferStaleProfile);
+ NamedRegionTimer T("inferStaleProfile", "inferring from stale profile",
+ "rewrite", "Rewrite passes", opts::InferStaleProfile);
if (!BF.hasCFG())
return false;
>From dd55c7d8479c6a6984df9911a7235898c46b65cc Mon Sep 17 00:00:00 2001
From: shawy <shawy at meta.com>
Date: Mon, 20 May 2024 10:11:56 -0700
Subject: [PATCH 3/9] [BOLT] Set InferStaleProfile timer to TimeRewrite
---
bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 33182d83449a2..55d3f710f9f59 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -707,8 +707,8 @@ void assignProfile(BinaryFunction &BF,
bool YAMLProfileReader::inferStaleProfile(
BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
- NamedRegionTimer T("inferStaleProfile", "inferring from stale profile",
- "rewrite", "Rewrite passes", opts::InferStaleProfile);
+ NamedRegionTimer T("inferStaleProfile", "stale profile inference",
+ "rewrite", "Rewrite passes", opts::TimeRewrite);
if (!BF.hasCFG())
return false;
>From e496030182eb2a59003db17f1ee56f2f19b86f70 Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Mon, 20 May 2024 10:21:26 -0700
Subject: [PATCH 4/9] [BOLT] [NFC] Formatting
---
bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 55d3f710f9f59..5420c683afc51 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -707,8 +707,8 @@ void assignProfile(BinaryFunction &BF,
bool YAMLProfileReader::inferStaleProfile(
BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
- NamedRegionTimer T("inferStaleProfile", "stale profile inference",
- "rewrite", "Rewrite passes", opts::TimeRewrite);
+ NamedRegionTimer T("inferStaleProfile", "stale profile inference", "rewrite",
+ "Rewrite passes", opts::TimeRewrite);
if (!BF.hasCFG())
return false;
>From ee3b661c3fce9ee2be8784a4d43984895d6a99bb Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Mon, 20 May 2024 14:24:42 -0700
Subject: [PATCH 5/9] [BOLT] Rm static keyword from opts::TimeRewrite
---
bolt/lib/Profile/StaleProfileMatching.cpp | 1 +
bolt/lib/Rewrite/RewriteInstance.cpp | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 5420c683afc51..712d9a121b5e1 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -43,6 +43,7 @@ using namespace llvm;
namespace opts {
+extern cl::opt<bool> TimeRewrite;
extern cl::OptionCategory BoltOptCategory;
cl::opt<bool>
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 85b39176754b6..56ce328a04255 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -235,7 +235,7 @@ UseGnuStack("use-gnu-stack",
cl::ZeroOrMore,
cl::cat(BoltCategory));
-static cl::opt<bool>
+cl::opt<bool>
TimeRewrite("time-rewrite",
cl::desc("print time spent in rewriting passes"), cl::Hidden,
cl::cat(BoltCategory));
>From ef246d45b665c4387fd13e00360c66d4219cc452 Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Tue, 21 May 2024 11:40:01 -0700
Subject: [PATCH 6/9] [BOLT] Formatting
---
bolt/lib/Rewrite/RewriteInstance.cpp | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 56ce328a04255..4b90622b80827 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -235,10 +235,9 @@ UseGnuStack("use-gnu-stack",
cl::ZeroOrMore,
cl::cat(BoltCategory));
-cl::opt<bool>
- TimeRewrite("time-rewrite",
- cl::desc("print time spent in rewriting passes"), cl::Hidden,
- cl::cat(BoltCategory));
+cl::opt<bool> TimeRewrite("time-rewrite",
+ cl::desc("print time spent in rewriting passes"),
+ cl::Hidden, cl::cat(BoltCategory));
static cl::opt<bool>
SequentialDisassembly("sequential-disassembly",
>From 93880d624c3d7d58b6c26495cecbcd61155bb4fd Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Tue, 21 May 2024 15:58:28 -0700
Subject: [PATCH 7/9] Move TimeRewrite opt to StaleProfileMatching
---
bolt/lib/Profile/StaleProfileMatching.cpp | 6 +++++-
bolt/lib/Rewrite/RewriteInstance.cpp | 5 +----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 712d9a121b5e1..1ce8397a1d25d 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -43,7 +43,7 @@ using namespace llvm;
namespace opts {
-extern cl::opt<bool> TimeRewrite;
+extern cl::OptionCategory BoltCategory;
extern cl::OptionCategory BoltOptCategory;
cl::opt<bool>
@@ -51,6 +51,10 @@ cl::opt<bool>
cl::desc("Infer counts from stale profile data."),
cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
+cl::opt<bool> TimeRewrite("time-rewrite",
+ cl::desc("print time spent in rewriting passes"),
+ cl::Hidden, cl::cat(BoltCategory));
+
cl::opt<unsigned> StaleMatchingMaxFuncSize(
"stale-matching-max-func-size",
cl::desc("The maximum size of a function to consider for inference."),
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4b90622b80827..718cf8eca9ae2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -86,6 +86,7 @@ extern cl::list<std::string> ReorderData;
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
extern cl::opt<bool> TerminalTrap;
extern cl::opt<bool> TimeBuild;
+extern cl::opt<bool> TimeRewrite;
cl::opt<bool> AllowStripped("allow-stripped",
cl::desc("allow processing of stripped binaries"),
@@ -235,10 +236,6 @@ UseGnuStack("use-gnu-stack",
cl::ZeroOrMore,
cl::cat(BoltCategory));
-cl::opt<bool> TimeRewrite("time-rewrite",
- cl::desc("print time spent in rewriting passes"),
- cl::Hidden, cl::cat(BoltCategory));
-
static cl::opt<bool>
SequentialDisassembly("sequential-disassembly",
cl::desc("performs disassembly sequentially"),
>From 4cda2814fb0708624fda27737feee5cfe916d8aa Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Tue, 21 May 2024 16:20:18 -0700
Subject: [PATCH 8/9] Moved TimeRewrite definition to CommandLineOpts
---
bolt/lib/Rewrite/RewriteInstance.cpp | 5 +----
bolt/lib/Utils/CommandLineOpts.cpp | 4 ++++
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4b90622b80827..718cf8eca9ae2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -86,6 +86,7 @@ extern cl::list<std::string> ReorderData;
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
extern cl::opt<bool> TerminalTrap;
extern cl::opt<bool> TimeBuild;
+extern cl::opt<bool> TimeRewrite;
cl::opt<bool> AllowStripped("allow-stripped",
cl::desc("allow processing of stripped binaries"),
@@ -235,10 +236,6 @@ UseGnuStack("use-gnu-stack",
cl::ZeroOrMore,
cl::cat(BoltCategory));
-cl::opt<bool> TimeRewrite("time-rewrite",
- cl::desc("print time spent in rewriting passes"),
- cl::Hidden, cl::cat(BoltCategory));
-
static cl::opt<bool>
SequentialDisassembly("sequential-disassembly",
cl::desc("performs disassembly sequentially"),
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp
index ba296c10c00ae..41c89bc8aeba4 100644
--- a/bolt/lib/Utils/CommandLineOpts.cpp
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -179,6 +179,10 @@ cl::opt<bool> TimeOpts("time-opts",
cl::desc("print time spent in each optimization"),
cl::cat(BoltOptCategory));
+cl::opt<bool> TimeRewrite("time-rewrite",
+ cl::desc("print time spent in rewriting passes"),
+ cl::Hidden, cl::cat(BoltCategory));
+
cl::opt<bool> UseOldText(
"use-old-text",
cl::desc("re-use space in old .text if possible (relocation mode)"),
>From 92d7ece5579b8b4a007cb5353b9659b0277709ba Mon Sep 17 00:00:00 2001
From: shawbyoung <shawbyoung at gmail.com>
Date: Wed, 22 May 2024 10:31:40 -0700
Subject: [PATCH 9/9] [BOLT] Remove TimeRewrite definition from
StaleProfileMatching
---
bolt/lib/Profile/StaleProfileMatching.cpp | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 1ce8397a1d25d..712d9a121b5e1 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -43,7 +43,7 @@ using namespace llvm;
namespace opts {
-extern cl::OptionCategory BoltCategory;
+extern cl::opt<bool> TimeRewrite;
extern cl::OptionCategory BoltOptCategory;
cl::opt<bool>
@@ -51,10 +51,6 @@ cl::opt<bool>
cl::desc("Infer counts from stale profile data."),
cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
-cl::opt<bool> TimeRewrite("time-rewrite",
- cl::desc("print time spent in rewriting passes"),
- cl::Hidden, cl::cat(BoltCategory));
-
cl::opt<unsigned> StaleMatchingMaxFuncSize(
"stale-matching-max-func-size",
cl::desc("The maximum size of a function to consider for inference."),
More information about the llvm-commits
mailing list