[BOLT] Detect .warm split functions as cold fragments (#93759)
CDSplit splits functions up to three ways: main fragment with no suffix, and fragments with .cold and .warm suffixes. Add .warm suffix to the regex used to recognize split fragments. Test Plan: updated register-fragments-bolt-symbols.s
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "llvm/Object/ELFObjectFile.h"
|
||||
#include "llvm/Object/ObjectFile.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/Regex.h"
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
@@ -596,6 +597,9 @@ private:
|
||||
|
||||
NameResolver NR;
|
||||
|
||||
// Regex object matching split function names.
|
||||
const Regex FunctionFragmentTemplate{"(.*)\\.(cold|warm)(\\.[0-9]+)?"};
|
||||
|
||||
friend class RewriteInstanceDiff;
|
||||
};
|
||||
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/Regex.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/Support/ToolOutputFile.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
@@ -945,9 +944,6 @@ void RewriteInstance::discoverFileObjects() {
|
||||
BinaryFunction *PreviousFunction = nullptr;
|
||||
unsigned AnonymousId = 0;
|
||||
|
||||
// Regex object for matching cold fragments.
|
||||
const Regex ColdFragment(".*\\.cold(\\.[0-9]+)?");
|
||||
|
||||
const auto SortedSymbolsEnd =
|
||||
LastSymbol == SortedSymbols.end() ? LastSymbol : std::next(LastSymbol);
|
||||
for (auto Iter = SortedSymbols.begin(); Iter != SortedSymbolsEnd; ++Iter) {
|
||||
@@ -1229,7 +1225,7 @@ void RewriteInstance::discoverFileObjects() {
|
||||
}
|
||||
|
||||
// Check if it's a cold function fragment.
|
||||
if (ColdFragment.match(SymName)) {
|
||||
if (FunctionFragmentTemplate.match(SymName)) {
|
||||
static bool PrintedWarning = false;
|
||||
if (!PrintedWarning) {
|
||||
PrintedWarning = true;
|
||||
@@ -1460,10 +1456,10 @@ void RewriteInstance::registerFragments() {
|
||||
for (StringRef Name : Function.getNames()) {
|
||||
StringRef BaseName = NR.restore(Name);
|
||||
const bool IsGlobal = BaseName == Name;
|
||||
const size_t ColdSuffixPos = BaseName.find(".cold");
|
||||
if (ColdSuffixPos == StringRef::npos)
|
||||
SmallVector<StringRef> Matches;
|
||||
if (!FunctionFragmentTemplate.match(BaseName, &Matches))
|
||||
continue;
|
||||
StringRef ParentName = BaseName.substr(0, ColdSuffixPos);
|
||||
StringRef ParentName = Matches[1];
|
||||
const BinaryData *BD = BC->getBinaryDataByName(ParentName);
|
||||
const uint64_t NumPossibleLocalParents =
|
||||
NR.getUniquifiedNameCount(ParentName);
|
||||
|
||||
@@ -3,8 +3,20 @@
|
||||
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %S/cdsplit-symbol-names.s -o %t.main.o
|
||||
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
|
||||
# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
|
||||
# RUN: sed -i 's|chain|chain/2|g' %t.fdata
|
||||
# RUN: llvm-strip --strip-unneeded %t.main.o
|
||||
|
||||
## Check warm fragment name matching (produced by cdsplit)
|
||||
# RUN: %clang %cflags %t.main.o -o %t.warm.exe -Wl,-q
|
||||
# RUN: llvm-bolt %t.warm.exe -o %t.warm.bolt --split-functions --split-strategy=cdsplit \
|
||||
# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
|
||||
# RUN: link_fdata %s %t.warm.bolt %t.preagg.warm PREAGGWARM
|
||||
# PREAGGWARM: B X:0 #chain.warm# 1 0
|
||||
# RUN: perf2bolt %t.warm.bolt -p %t.preagg.warm --pa -o %t.warm.fdata -w %t.warm.yaml \
|
||||
# RUN: -v=1 | FileCheck %s --check-prefix=CHECK-BOLT-WARM
|
||||
|
||||
# CHECK-BOLT-WARM: marking chain.warm/1(*2) as a fragment of chain
|
||||
|
||||
# RUN: sed -i 's|chain|chain/2|g' %t.fdata
|
||||
# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
|
||||
# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
|
||||
# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
|
||||
|
||||
Reference in New Issue
Block a user