[PATCH] D156176: [BOLT] Add blocks order kind to YAML profile header
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 21:33:29 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e0d08e87227: [BOLT] Add blocks order kind to YAML profile header (authored by Amir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156176/new/
https://reviews.llvm.org/D156176
Files:
bolt/include/bolt/Profile/ProfileYAMLMapping.h
bolt/lib/Profile/YAMLProfileReader.cpp
bolt/lib/Profile/YAMLProfileWriter.cpp
bolt/test/yaml-profile-kind.c
Index: bolt/test/yaml-profile-kind.c
===================================================================
--- /dev/null
+++ bolt/test/yaml-profile-kind.c
@@ -0,0 +1,13 @@
+/* This test checks the handling of YAML profile with different block orders.
+# RUN: %clang %cflags %s -o %t.exe
+# RUN: link_fdata %s %t.exe %t.fdata
+# RUN: llvm-bolt %t.exe -o /dev/null -data %t.fdata -w %t.yaml
+# RUN: FileCheck %s --input-file %t.yaml --check-prefix=CHECK-BINARY
+# CHECK-BINARY: dfs-order: false
+# RUN: llvm-bolt %t.exe -o /dev/null -data %t.fdata -w %t.yaml --profile-use-dfs
+# RUN: FileCheck %s --input-file %t.yaml --check-prefix=CHECK-DFS
+# CHECK-DFS: dfs-order: true
+
+# FDATA: 0 [unknown] 0 1 main 0 0 0
+*/
+int main() { return 0; }
Index: bolt/lib/Profile/YAMLProfileWriter.cpp
===================================================================
--- bolt/lib/Profile/YAMLProfileWriter.cpp
+++ bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -188,6 +188,7 @@
std::optional<StringRef> BuildID = BC.getFileBuildID();
BP.Header.Id = BuildID ? std::string(*BuildID) : "<unknown>";
BP.Header.Origin = std::string(RI.getProfileReader()->getReaderName());
+ BP.Header.IsDFSOrder = opts::ProfileUseDFS;
StringSet<> EventNames = RI.getProfileReader()->getEventNames();
if (!EventNames.empty()) {
Index: bolt/lib/Profile/YAMLProfileReader.cpp
===================================================================
--- bolt/lib/Profile/YAMLProfileReader.cpp
+++ bolt/lib/Profile/YAMLProfileReader.cpp
@@ -79,6 +79,7 @@
BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
BinaryContext &BC = BF.getBinaryContext();
+ const bool IsDFSOrder = YamlBP.Header.IsDFSOrder;
bool ProfileMatched = true;
uint64_t MismatchedBlocks = 0;
uint64_t MismatchedCalls = 0;
@@ -94,7 +95,7 @@
FuncRawBranchCount += YamlSI.Count;
BF.setRawBranchCount(FuncRawBranchCount);
- if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash(opts::ProfileUseDFS)) {
+ if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash(IsDFSOrder)) {
if (opts::Verbosity >= 1)
errs() << "BOLT-WARNING: function hash mismatch\n";
ProfileMatched = false;
@@ -107,7 +108,7 @@
}
BinaryFunction::BasicBlockOrderType Order;
- if (opts::ProfileUseDFS)
+ if (IsDFSOrder)
llvm::copy(BF.dfs(), std::back_inserter(Order));
else
llvm::copy(BF.getLayout().blocks(), std::back_inserter(Order));
@@ -346,7 +347,7 @@
// Recompute hash once per function.
if (!opts::IgnoreHash)
- Function.computeHash(opts::ProfileUseDFS);
+ Function.computeHash(YamlBP.Header.IsDFSOrder);
for (StringRef FunctionName : Function.getNames()) {
auto PI = ProfileNameToProfile.find(FunctionName);
Index: bolt/include/bolt/Profile/ProfileYAMLMapping.h
===================================================================
--- bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -187,6 +187,7 @@
// Type of the profile.
std::string Origin; // How the profile was obtained.
std::string EventNames; // Events used for sample profile.
+ bool IsDFSOrder{true}; // Whether using DFS block order in function profile
};
} // end namespace bolt
@@ -198,6 +199,7 @@
YamlIO.mapRequired("profile-flags", Header.Flags);
YamlIO.mapOptional("profile-origin", Header.Origin);
YamlIO.mapOptional("profile-events", Header.EventNames);
+ YamlIO.mapOptional("dfs-order", Header.IsDFSOrder);
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156176.543814.patch
Type: text/x-patch
Size: 3514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230725/7121e7d1/attachment.bin>
More information about the llvm-commits
mailing list