Skip to content

Commit 3447dc4

Browse files
committed
Merge branch 'main' into reverse-null
2 parents 87742d6 + 36ad072 commit 3447dc4

File tree

5,607 files changed

+471731
-490960
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

5,607 files changed

+471731
-490960
lines changed

.github/new-prs-labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ mlgo:
668668
- llvm/lib/CodeGen/ML*
669669
- llvm/unittests/CodeGen/ML*
670670
- llvm/test/CodeGen/MLRegAlloc/**
671-
- llvm/utils/mlgo-utils/*
671+
- llvm/utils/mlgo-utils/**
672672

673673
tools:llvm-exegesis:
674674
- llvm/tools/llvm-exegesis/**

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ jobs:
242242
- { config: mingw-dll, mingw: true }
243243
- { config: mingw-static, mingw: true }
244244
- { config: mingw-dll-i686, mingw: true }
245+
- { config: mingw-incomplete-sysroot, mingw: true }
245246
steps:
246247
- uses: actions/checkout@v4
247248
- name: Install dependencies
@@ -260,6 +261,12 @@ jobs:
260261
del llvm-mingw*.zip
261262
mv llvm-mingw* c:\llvm-mingw
262263
echo "c:\llvm-mingw\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
264+
- name: Simulate a from-scratch build of llvm-mingw
265+
if: ${{ matrix.config == 'mingw-incomplete-sysroot' }}
266+
run: |
267+
rm -r c:\llvm-mingw\include\c++
268+
rm -r c:\llvm-mingw\*-w64-mingw32\lib\libc++*
269+
rm -r c:\llvm-mingw\*-w64-mingw32\lib\libunwind*
263270
- name: Add Git Bash to the path
264271
run: |
265272
echo "c:\Program Files\Git\usr\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append

.github/workflows/pr-code-format.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
jobs:
1313
code_formatter:
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 30
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
18+
cancel-in-progress: true
1519
if: github.repository == 'llvm/llvm-project'
1620
steps:
1721
- name: Fetch LLVM sources

.github/workflows/release-binaries-save-stage/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
required: true
1111
type: 'string'
1212

13+
permissions:
14+
contents: read
15+
1316
runs:
1417
using: "composite"
1518
steps:
@@ -18,6 +21,9 @@ runs:
1821
- name: Package Build and Source Directories
1922
shell: bash
2023
run: |
24+
# Remove .git/config to avoid leaking GITHUB_TOKEN stored there.
25+
# See https://unit42.paloaltonetworks.com/github-repo-artifacts-leak-tokens/
26+
rm -Rf .git/config
2127
# Windows does not support symlinks, so we need to dereference them.
2228
tar --exclude build/ ${{ (runner.os == 'Windows' && '-h') || '' }} -c . | zstd -T0 -c > ../llvm-project.tar.zst
2329
mv ../llvm-project.tar.zst .

bolt/include/bolt/Utils/Utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ std::string getEscapedName(const StringRef &Name);
4141
/// Return the unescaped name
4242
std::string getUnescapedName(const StringRef &Name);
4343

44+
/// Return a common part for a given \p Name wrt a given \p Suffixes list.
45+
/// Preserve the suffix if \p KeepSuffix is set, only dropping characters
46+
/// following it, otherwise drop the suffix as well.
47+
std::optional<StringRef> getCommonName(const StringRef Name, bool KeepSuffix,
48+
ArrayRef<StringRef> Suffixes);
4449
/// LTO-generated function names take a form:
4550
///
4651
/// <function_name>.lto_priv.<decimal_number>/...

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ MaxSamples("max-samples",
8888
cl::cat(AggregatorCategory));
8989

9090
extern cl::opt<opts::ProfileFormatKind> ProfileFormat;
91-
extern cl::opt<bool> ProfileUsePseudoProbes;
91+
extern cl::opt<bool> ProfileWritePseudoProbes;
9292
extern cl::opt<std::string> SaveProfile;
9393

9494
cl::opt<bool> ReadPreAggregated(
@@ -2300,7 +2300,7 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
23002300
yaml::bolt::BinaryProfile BP;
23012301

23022302
const MCPseudoProbeDecoder *PseudoProbeDecoder =
2303-
opts::ProfileUsePseudoProbes ? BC.getPseudoProbeDecoder() : nullptr;
2303+
opts::ProfileWritePseudoProbes ? BC.getPseudoProbeDecoder() : nullptr;
23042304

23052305
// Fill out the header info.
23062306
BP.Header.Version = 1;
@@ -2427,11 +2427,15 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
24272427
}
24282428
}
24292429
}
2430-
// Drop blocks without a hash, won't be useful for stale matching.
2431-
llvm::erase_if(YamlBF.Blocks,
2432-
[](const yaml::bolt::BinaryBasicBlockProfile &YamlBB) {
2433-
return YamlBB.Hash == (yaml::Hex64)0;
2434-
});
2430+
// Skip printing if there's no profile data
2431+
llvm::erase_if(
2432+
YamlBF.Blocks, [](const yaml::bolt::BinaryBasicBlockProfile &YamlBB) {
2433+
auto HasCount = [](const auto &SI) { return SI.Count; };
2434+
bool HasAnyCount = YamlBB.ExecCount ||
2435+
llvm::any_of(YamlBB.Successors, HasCount) ||
2436+
llvm::any_of(YamlBB.CallSites, HasCount);
2437+
return !HasAnyCount;
2438+
});
24352439
BP.Functions.emplace_back(YamlBF);
24362440
}
24372441
}

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ llvm::cl::opt<bool>
4949
llvm::cl::opt<bool> ProfileUseDFS("profile-use-dfs",
5050
cl::desc("use DFS order for YAML profile"),
5151
cl::Hidden, cl::cat(BoltOptCategory));
52-
53-
llvm::cl::opt<bool> ProfileUsePseudoProbes(
54-
"profile-use-pseudo-probes",
55-
cl::desc("Use pseudo probes for profile generation and matching"),
56-
cl::Hidden, cl::cat(BoltOptCategory));
5752
} // namespace opts
5853

5954
namespace llvm {
@@ -373,6 +368,7 @@ Error YAMLProfileReader::preprocessProfile(BinaryContext &BC) {
373368
return errorCodeToError(EC);
374369
}
375370
yaml::Input YamlInput(MB.get()->getBuffer());
371+
YamlInput.setAllowUnknownKeys(true);
376372

377373
// Consume YAML file.
378374
YamlInput >> YamlBP;

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "bolt/Profile/DataAggregator.h"
1414
#include "bolt/Profile/ProfileReaderBase.h"
1515
#include "bolt/Rewrite/RewriteInstance.h"
16+
#include "bolt/Utils/CommandLineOpts.h"
1617
#include "llvm/Support/CommandLine.h"
1718
#include "llvm/Support/FileSystem.h"
1819
#include "llvm/Support/raw_ostream.h"
@@ -21,8 +22,12 @@
2122
#define DEBUG_TYPE "bolt-prof"
2223

2324
namespace opts {
24-
extern llvm::cl::opt<bool> ProfileUseDFS;
25-
extern llvm::cl::opt<bool> ProfileUsePseudoProbes;
25+
using namespace llvm;
26+
extern cl::opt<bool> ProfileUseDFS;
27+
cl::opt<bool> ProfileWritePseudoProbes(
28+
"profile-write-pseudo-probes",
29+
cl::desc("Use pseudo probes in profile generation"), cl::Hidden,
30+
cl::cat(BoltOptCategory));
2631
} // namespace opts
2732

2833
namespace llvm {
@@ -59,7 +64,7 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
5964
yaml::bolt::BinaryFunctionProfile YamlBF;
6065
const BinaryContext &BC = BF.getBinaryContext();
6166
const MCPseudoProbeDecoder *PseudoProbeDecoder =
62-
opts::ProfileUsePseudoProbes ? BC.getPseudoProbeDecoder() : nullptr;
67+
opts::ProfileWritePseudoProbes ? BC.getPseudoProbeDecoder() : nullptr;
6368

6469
const uint16_t LBRProfile = BF.getProfileFlags() & BinaryFunction::PF_LBR;
6570

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "bolt/Rewrite/MetadataRewriter.h"
1515
#include "bolt/Rewrite/MetadataRewriters.h"
1616
#include "bolt/Utils/CommandLineOpts.h"
17+
#include "bolt/Utils/Utils.h"
1718
#include "llvm/IR/Function.h"
1819
#include "llvm/MC/MCPseudoProbe.h"
1920
#include "llvm/Support/CommandLine.h"
@@ -49,7 +50,7 @@ static cl::opt<PrintPseudoProbesOptions> PrintPseudoProbes(
4950
clEnumValN(PPP_All, "all", "enable all debugging printout")),
5051
cl::Hidden, cl::cat(BoltCategory));
5152

52-
extern cl::opt<bool> ProfileUsePseudoProbes;
53+
extern cl::opt<bool> ProfileWritePseudoProbes;
5354
} // namespace opts
5455

5556
namespace {
@@ -71,7 +72,8 @@ class PseudoProbeRewriter final : public MetadataRewriter {
7172

7273
/// Parse .pseudo_probe_desc section and .pseudo_probe section
7374
/// Setup Pseudo probe decoder
74-
void parsePseudoProbe();
75+
/// If \p ProfiledOnly is set, only parse records for functions with profile.
76+
void parsePseudoProbe(bool ProfiledOnly = false);
7577

7678
/// PseudoProbe decoder
7779
std::shared_ptr<MCPseudoProbeDecoder> ProbeDecoderPtr;
@@ -90,21 +92,21 @@ class PseudoProbeRewriter final : public MetadataRewriter {
9092
};
9193

9294
Error PseudoProbeRewriter::preCFGInitializer() {
93-
if (opts::ProfileUsePseudoProbes)
94-
parsePseudoProbe();
95+
if (opts::ProfileWritePseudoProbes)
96+
parsePseudoProbe(true);
9597

9698
return Error::success();
9799
}
98100

99101
Error PseudoProbeRewriter::postEmitFinalizer() {
100-
if (!opts::ProfileUsePseudoProbes)
102+
if (!opts::ProfileWritePseudoProbes)
101103
parsePseudoProbe();
102104
updatePseudoProbes();
103105

104106
return Error::success();
105107
}
106108

107-
void PseudoProbeRewriter::parsePseudoProbe() {
109+
void PseudoProbeRewriter::parsePseudoProbe(bool ProfiledOnly) {
108110
MCPseudoProbeDecoder &ProbeDecoder(*ProbeDecoderPtr);
109111
PseudoProbeDescSection = BC.getUniqueSectionByName(".pseudo_probe_desc");
110112
PseudoProbeSection = BC.getUniqueSectionByName(".pseudo_probe");
@@ -133,10 +135,22 @@ void PseudoProbeRewriter::parsePseudoProbe() {
133135

134136
MCPseudoProbeDecoder::Uint64Set GuidFilter;
135137
MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
138+
SmallVector<StringRef, 0> Suffixes(
139+
{".destroy", ".resume", ".llvm.", ".cold", ".warm"});
136140
for (const BinaryFunction *F : BC.getAllBinaryFunctions()) {
141+
bool HasProfile = F->hasProfileAvailable();
137142
for (const MCSymbol *Sym : F->getSymbols()) {
138-
FuncStartAddrs[Function::getGUID(NameResolver::restore(Sym->getName()))] =
139-
F->getAddress();
143+
StringRef SymName = Sym->getName();
144+
for (auto Name : {std::optional(NameResolver::restore(SymName)),
145+
getCommonName(SymName, false, Suffixes)}) {
146+
if (!Name)
147+
continue;
148+
SymName = *Name;
149+
uint64_t GUID = Function::getGUID(SymName);
150+
FuncStartAddrs[GUID] = F->getAddress();
151+
if (ProfiledOnly && HasProfile)
152+
GuidFilter.insert(GUID);
153+
}
140154
}
141155
}
142156
Contents = PseudoProbeSection->getContents();
@@ -155,13 +169,25 @@ void PseudoProbeRewriter::parsePseudoProbe() {
155169
ProbeDecoder.printProbesForAllAddresses(outs());
156170
}
157171

158-
for (const auto &FuncDesc : ProbeDecoder.getGUID2FuncDescMap()) {
159-
uint64_t GUID = FuncDesc.FuncGUID;
160-
if (!FuncStartAddrs.contains(GUID))
161-
continue;
162-
BinaryFunction *BF = BC.getBinaryFunctionAtAddress(FuncStartAddrs[GUID]);
163-
assert(BF);
164-
BF->setGUID(GUID);
172+
const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap();
173+
// Checks GUID in GUID2Func and returns it if it's present or null otherwise.
174+
auto checkGUID = [&](StringRef SymName) -> uint64_t {
175+
uint64_t GUID = Function::getGUID(SymName);
176+
if (GUID2Func.find(GUID) == GUID2Func.end())
177+
return 0;
178+
return GUID;
179+
};
180+
for (BinaryFunction *F : BC.getAllBinaryFunctions()) {
181+
for (const MCSymbol *Sym : F->getSymbols()) {
182+
StringRef SymName = NameResolver::restore(Sym->getName());
183+
uint64_t GUID = checkGUID(SymName);
184+
std::optional<StringRef> CommonName =
185+
getCommonName(SymName, false, Suffixes);
186+
if (!GUID && CommonName)
187+
GUID = checkGUID(*CommonName);
188+
if (GUID)
189+
F->setGUID(GUID);
190+
}
165191
}
166192
}
167193

bolt/lib/Utils/Utils.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ std::string getUnescapedName(const StringRef &Name) {
6666
return Output;
6767
}
6868

69-
std::optional<StringRef> getLTOCommonName(const StringRef Name) {
70-
for (StringRef Suffix : {".__uniq.", ".lto_priv.", ".constprop.", ".llvm."}) {
69+
std::optional<StringRef> getCommonName(const StringRef Name, bool KeepSuffix,
70+
ArrayRef<StringRef> Suffixes) {
71+
for (StringRef Suffix : Suffixes) {
7172
size_t LTOSuffixPos = Name.find(Suffix);
7273
if (LTOSuffixPos != StringRef::npos)
73-
return Name.substr(0, LTOSuffixPos + Suffix.size());
74+
return Name.substr(0, LTOSuffixPos + (KeepSuffix ? Suffix.size() : 0));
7475
}
7576
return std::nullopt;
7677
}
7778

79+
std::optional<StringRef> getLTOCommonName(const StringRef Name) {
80+
return getCommonName(Name, true,
81+
{".__uniq.", ".lto_priv.", ".constprop.", ".llvm."});
82+
}
83+
7884
std::optional<uint8_t> readDWARFExpressionTargetReg(StringRef ExprBytes) {
7985
uint8_t Opcode = ExprBytes[0];
8086
if (Opcode == dwarf::DW_CFA_def_cfa_expression)

bolt/test/X86/pseudoprobe-decoding-inline.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
# PREAGG: B X:0 #main# 1 0
77
## Check pseudo-probes in regular YAML profile (non-BOLTed binary)
88
# RUN: link_fdata %s %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin %t.preagg PREAGG
9-
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata --profile-use-pseudo-probes
9+
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata --profile-write-pseudo-probes
1010
# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-YAML
1111
## Check pseudo-probes in BAT YAML profile (BOLTed binary)
1212
# RUN: link_fdata %s %t.bolt %t.preagg2 PREAGG
13-
# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2 --profile-use-pseudo-probes
13+
# RUN: perf2bolt %t.bolt -p %t.preagg2 --pa -w %t.yaml2 -o %t.fdata2 --profile-write-pseudo-probes
1414
# RUN: FileCheck --input-file %t.yaml2 %s --check-prefix CHECK-YAML
1515
# CHECK-YAML: name: bar
1616
# CHECK-YAML: - bid: 0
@@ -30,7 +30,7 @@
3030
# CHECK-YAML: guid: 0xDB956436E78DD5FA
3131
# CHECK-YAML: pseudo_probe_desc_hash: 0x10000FFFFFFFF
3232
#
33-
## Check that without --profile-use-pseudo-probes option, no pseudo probes are
33+
## Check that without --profile-write-pseudo-probes option, no pseudo probes are
3434
## generated
3535
# RUN: perf2bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin -p %t.preagg --pa -w %t.yaml -o %t.fdata
3636
# RUN: FileCheck --input-file %t.yaml %s --check-prefix CHECK-NO-OPT

bolt/test/X86/yaml-unknown-keys.test

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## Test that BOLT gracefully handles a YAML profile with unknown keys.
2+
3+
# REQUIRES: system-linux
4+
# RUN: split-file %s %t
5+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %t/main.s -o %t.o
6+
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
7+
# RUN: llvm-bolt %t.exe -o %t.null --data %t/profile.yaml \
8+
# RUN: --profile-ignore-hash -v=1 2>&1 | FileCheck %s
9+
# CHECK: warning: unknown key 'unknown-header-key'
10+
# CHECK: warning: unknown key 'unknown_succ_key'
11+
# CHECK: warning: unknown key 'unknown_block_key'
12+
# CHECK: warning: unknown key 'unknown_function_key'
13+
# CHECK: warning: unknown key 'unknown_toplev_key'
14+
#--- main.s
15+
.globl main
16+
.type main, %function
17+
main:
18+
.cfi_startproc
19+
cmpl $0x0, %eax
20+
jne .LBB0
21+
.LBB0:
22+
retq
23+
.cfi_endproc
24+
.size main, .-main
25+
#--- profile.yaml
26+
---
27+
header:
28+
profile-version: 1
29+
binary-name: 'yaml-multiple-profiles.test.tmp.exe'
30+
binary-build-id: '<unknown>'
31+
profile-flags: [ lbr ]
32+
profile-origin: branch profile reader
33+
profile-events: ''
34+
dfs-order: false
35+
unknown-header-key: true
36+
functions:
37+
- name: 'main'
38+
fid: 1
39+
hash: 0x50BBA3441D436491
40+
exec: 1
41+
nblocks: 1
42+
blocks:
43+
- bid: 0
44+
insns: 2
45+
hash: 0x4D4D8FAF7D4C0000
46+
succ: [ { bid: 1, cnt: 0, unknown_succ_key: 0x10 } ]
47+
unknown_block_key: [ ]
48+
unknown_function_key: 1
49+
unknown_toplev_key: ''
50+
...

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ int main(int argc, char **argv) {
392392
if (std::error_code EC = MB.getError())
393393
report_error(InputDataFilename, EC);
394394
yaml::Input YamlInput(MB.get()->getBuffer());
395+
YamlInput.setAllowUnknownKeys(true);
395396

396397
errs() << "Merging data from " << InputDataFilename << "...\n";
397398

0 commit comments

Comments
 (0)