Skip to content

Commit 4315415

Browse files
committed
Merge remote-tracking branch 'origin/main' into pr/zhinx-subreg
2 parents 37bd470 + ee40ffd commit 4315415

File tree

1,093 files changed

+56835
-23228
lines changed

Some content is hidden

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

1,093 files changed

+56835
-23228
lines changed

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: 0 additions & 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 {

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

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import textwrap
1818

1919
# FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
20-
from typing import Optional, Tuple
20+
from typing import Optional, Tuple, Match
2121

2222

2323
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
@@ -511,7 +511,7 @@ def has_auto_fix(check_name: str) -> str:
511511

512512
return ""
513513

514-
def process_doc(doc_file: Tuple[str, str]) -> Tuple[str, Optional[re.Match[str]]]:
514+
def process_doc(doc_file: Tuple[str, str]) -> Tuple[str, Optional[Match[str]]]:
515515
check_name = doc_file[0] + "-" + doc_file[1].replace(".rst", "")
516516

517517
with io.open(os.path.join(docs_dir, *doc_file), "r", encoding="utf8") as doc:

clang-tools-extra/docs/clang-tidy/Contributing.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,20 @@ matching expressions to simplify your matcher.
344344
clang-query> let c1 cxxRecordDecl()
345345
clang-query> match c1
346346
347-
Alternatively, pressing the tab key after a previous matcher's open parentheses would also
348-
show which matchers can be chained with the previous matcher, though some matchers that work
349-
may not be listed.
350-
351-
Just like breaking up a huge function into smaller chunks with intention-revealing names
352-
can help you understand a complex algorithm, breaking up a matcher into smaller matchers
353-
with intention-revealing names can help you understand a complicated matcher.
354-
355-
Once you have a working clang-query matcher, the C++ API matchers will be the same or similar
356-
to your interactively constructed matcher (there can be cases where they differ slightly).
357-
You can use local variables to preserve your intention-revealing names that you applied
358-
to nested matchers.
347+
Alternatively, pressing the tab key after a previous matcher's open parentheses
348+
would also show which matchers can be chained with the previous matcher,
349+
though some matchers that work may not be listed. Note that tab completion
350+
does not currently work on Windows.
351+
352+
Just like breaking up a huge function into smaller chunks with
353+
intention-revealing names can help you understand a complex algorithm, breaking
354+
up a matcher into smaller matchers with intention-revealing names can help
355+
you understand a complicated matcher.
356+
357+
Once you have a working :program:`clang-query` matcher, the C++ API matchers
358+
will be the same or similar to your interactively constructed matcher (there
359+
can be cases where they differ slightly). You can use local variables to preserve
360+
your intention-revealing names that you applied to nested matchers.
359361

360362
Creating private matchers
361363
^^^^^^^^^^^^^^^^^^^^^^^^^

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ void lambda_value_reference_auxiliary_var(T&& t) {
187187
namespace deleted_functions {
188188

189189
template <typename T>
190-
void f(T &&) = delete;
190+
void f(T &&t) = delete;
191191

192192
struct S {
193193
template <typename T>
194-
S(T &&) = delete;
194+
S(T &&t) = delete;
195195

196196
template <typename T>
197-
void operator&(T &&) = delete;
197+
void operator&(T &&t) = delete;
198198
};
199199

200200
} // namespace deleted_functions

clang/docs/OpenMPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ implementation.
306306
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
307307
| misc | OMP_NUM_TEAMS and OMP_TEAMS_THREAD_LIMIT env vars | :good:`done` | D138769 |
308308
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
309-
| misc | 'target_device' selector in context specifier | :none:`unclaimed` | |
309+
| misc | 'target_device' selector in context specifier | :none:`worked on` | |
310310
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
311311
| misc | begin/end declare variant | :good:`done` | D71179 |
312312
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/docs/RealtimeSanitizer.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,53 @@ non-zero exit code.
8383
#13 0x00010230dd64 in main main.cpp:9
8484
#14 0x0001958960dc (<unknown module>)
8585
#15 0x2f557ffffffffffc (<unknown module>)
86+
87+
Disabling
88+
---------
89+
90+
In some circumstances, you may want to suppress error reporting in a specific scope.
91+
92+
In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively.
93+
94+
.. code-block:: c++
95+
96+
#include <sanitizer/rtsan_interface.h>
97+
98+
void process(const std::vector<float>& buffer) [[clang::nonblocking]] {
99+
{
100+
__rtsan::ScopedDisabler d;
101+
...
102+
}
103+
}
104+
105+
If RealtimeSanitizer is not enabled at compile time (i.e., the code is not compiled with the ``-fsanitize=realtime`` flag), the ``ScopedDisabler`` is compiled as a no-op.
106+
107+
In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to manually disable and re-enable RealtimeSanitizer checks.
108+
109+
.. code-block:: c++
110+
111+
#include <sanitizer/rtsan_interface.h>
112+
113+
int process(const float* buffer) [[clang::nonblocking]]
114+
{
115+
{
116+
__rtsan_disable();
117+
118+
...
119+
120+
__rtsan_enable();
121+
}
122+
}
123+
124+
Each call to ``__rtsan_disable()`` must be paired with a subsequent call to ``__rtsan_enable()`` to restore normal sanitizer functionality. If a corresponding ``rtsan_enable()`` call is not made, the behavior is undefined.
125+
126+
Compile-time sanitizer detection
127+
--------------------------------
128+
129+
Clang provides the pre-processor macro ``__has_feature`` which may be used to detect if RealtimeSanitizer is enabled at compile-time.
130+
131+
.. code-block:: c++
132+
133+
#if defined(__has_feature) && __has_feature(realtime_sanitizer)
134+
...
135+
#endif

0 commit comments

Comments
 (0)