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

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 16:59:44 PDT 2024


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

Only apply stale matching if the binary function is in CFG state, i.e.
has basic blocks.

Test Plan:
Updated bolt/test/X86/reader-stale-yaml.test


>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] [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



More information about the llvm-commits mailing list