[llvm] [BOLT] Check BF state in stale matching (PR #85339)

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 10:55:26 PDT 2024


https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/85339

>From 6d01a58eeee96a27258725f9d1e8582e94df4375 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Thu, 14 Mar 2024 16:44:01 -0700
Subject: [PATCH 1/2] [BOLT] Check BF state in stale matching

---
 bolt/lib/Profile/StaleProfileMatching.cpp | 4 ++++
 bolt/test/X86/reader-stale-yaml.test      | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index 631ccaec6ae614..e8ccc972f90991 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -25,6 +25,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "bolt/Core/BinaryFunction.h"
 #include "bolt/Core/HashUtilities.h"
 #include "bolt/Profile/YAMLProfileReader.h"
 #include "llvm/ADT/Bitfields.h"
@@ -705,6 +706,9 @@ void assignProfile(BinaryFunction &BF,
 
 bool YAMLProfileReader::inferStaleProfile(
     BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
+  if (BF.getState() != BinaryFunction::State::CFG)
+    return false;
+
   LLVM_DEBUG(dbgs() << "BOLT-INFO: applying profile inference for "
                     << "\"" << BF.getPrintName() << "\"\n");
 
diff --git a/bolt/test/X86/reader-stale-yaml.test b/bolt/test/X86/reader-stale-yaml.test
index 533ed917c1aeb0..f4a8865b1f9a46 100644
--- a/bolt/test/X86/reader-stale-yaml.test
+++ b/bolt/test/X86/reader-stale-yaml.test
@@ -14,6 +14,10 @@ RUN:   --profile-ignore-hash=1 --profile-use-dfs=0 --debug-only=bolt-prof 2>&1 |
 RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
 RUN:   --print-cfg --print-only=SolveCubic --infer-stale-profile=1 \
 RUN:   --profile-ignore-hash=1 --profile-use-dfs=0 --debug-only=bolt-prof 2>&1 | FileCheck %s -check-prefix=CHECK2
+# Testing skipped function
+RUN: llvm-bolt %t.exe -o %t.null --b %p/Inputs/blarge_profile_stale.yaml \
+RUN:   --print-cfg --print-only=usqrt --infer-stale-profile=1 --skip-funcs=usqrt \
+RUN:   --profile-ignore-hash=1 --profile-use-dfs=0
 
 CHECK0: BOLT-INFO: 2 out of 7 functions in the binary (28.6%) have non-empty execution profile
 CHECK0: BOLT-WARNING: 2 (100.0% of all profiled) functions have invalid (possibly stale) profile

>From c74890f1f8e0174211e3d9b4632ce7d08208091a Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Fri, 15 Mar 2024 10:53:13 -0700
Subject: [PATCH 2/2] fixup! [BOLT] Check BF state in stale matching

---
 bolt/lib/Profile/StaleProfileMatching.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/bolt/lib/Profile/StaleProfileMatching.cpp b/bolt/lib/Profile/StaleProfileMatching.cpp
index e8ccc972f90991..016962ff34d8df 100644
--- a/bolt/lib/Profile/StaleProfileMatching.cpp
+++ b/bolt/lib/Profile/StaleProfileMatching.cpp
@@ -25,7 +25,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "bolt/Core/BinaryFunction.h"
 #include "bolt/Core/HashUtilities.h"
 #include "bolt/Profile/YAMLProfileReader.h"
 #include "llvm/ADT/Bitfields.h"
@@ -706,7 +705,7 @@ void assignProfile(BinaryFunction &BF,
 
 bool YAMLProfileReader::inferStaleProfile(
     BinaryFunction &BF, const yaml::bolt::BinaryFunctionProfile &YamlBF) {
-  if (BF.getState() != BinaryFunction::State::CFG)
+  if (!BF.hasCFG())
     return false;
 
   LLVM_DEBUG(dbgs() << "BOLT-INFO: applying profile inference for "



More information about the llvm-commits mailing list