Skip to content

Commit b14272f

Browse files
author
Pavel V Chupin
committed
Merge commit '8b626a2caa672a174829105ff7749d8d9a080f2a' into pulldown
2 parents 97845e9 + 8b626a2 commit b14272f

File tree

212 files changed

+2595
-1313
lines changed

Some content is hidden

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

212 files changed

+2595
-1313
lines changed

bolt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(BOLT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
55
set(CMAKE_CXX_STANDARD 14)
66

77
set(BOLT_ENABLE_RUNTIME OFF)
8-
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
8+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
99
set(BOLT_ENABLE_RUNTIME ON)
1010
endif()
1111

bolt/include/bolt/Profile/Heatmap.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@
1212
#include "llvm/ADT/StringRef.h"
1313
#include <cstdint>
1414
#include <map>
15+
#include <vector>
1516

1617
namespace llvm {
1718
class raw_ostream;
1819

1920
namespace bolt {
2021

22+
/// Struct representing a section name and its address range in the binary.
23+
struct SectionNameAndRange {
24+
StringRef Name;
25+
uint64_t BeginAddress;
26+
uint64_t EndAddress;
27+
};
28+
2129
class Heatmap {
2230
/// Number of bytes per entry in the heat map.
2331
size_t BucketSize;
@@ -34,11 +42,15 @@ class Heatmap {
3442
/// Map buckets to the number of samples.
3543
std::map<uint64_t, uint64_t> Map;
3644

45+
/// Map section names to their address range.
46+
const std::vector<SectionNameAndRange> TextSections;
47+
3748
public:
3849
explicit Heatmap(uint64_t BucketSize = 4096, uint64_t MinAddress = 0,
39-
uint64_t MaxAddress = std::numeric_limits<uint64_t>::max())
40-
: BucketSize(BucketSize), MinAddress(MinAddress),
41-
MaxAddress(MaxAddress){};
50+
uint64_t MaxAddress = std::numeric_limits<uint64_t>::max(),
51+
std::vector<SectionNameAndRange> TextSections = {})
52+
: BucketSize(BucketSize), MinAddress(MinAddress), MaxAddress(MaxAddress),
53+
TextSections(TextSections) {}
4254

4355
inline bool ignoreAddress(uint64_t Address) const {
4456
return (Address > MaxAddress) || (Address < MinAddress);
@@ -65,6 +77,10 @@ class Heatmap {
6577

6678
void printCDF(raw_ostream &OS) const;
6779

80+
void printSectionHotness(StringRef Filename) const;
81+
82+
void printSectionHotness(raw_ostream &OS) const;
83+
6884
size_t size() const { return Map.size(); }
6985
};
7086

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ namespace {
116116
const char TimerGroupName[] = "aggregator";
117117
const char TimerGroupDesc[] = "Aggregator";
118118

119+
std::vector<SectionNameAndRange> getTextSections(const BinaryContext *BC) {
120+
std::vector<SectionNameAndRange> sections;
121+
for (BinarySection &Section : BC->sections()) {
122+
if (!Section.isText())
123+
continue;
124+
if (Section.getSize() == 0)
125+
continue;
126+
sections.push_back(
127+
{Section.getName(), Section.getAddress(), Section.getEndAddress()});
128+
}
129+
std::sort(sections.begin(), sections.end(),
130+
[](const SectionNameAndRange &A, const SectionNameAndRange &B) {
131+
return A.BeginAddress < B.BeginAddress;
132+
});
133+
return sections;
134+
}
119135
}
120136

121137
constexpr uint64_t DataAggregator::KernelBaseAddr;
@@ -1292,7 +1308,7 @@ std::error_code DataAggregator::printLBRHeatMap() {
12921308
opts::HeatmapMinAddress = KernelBaseAddr;
12931309
}
12941310
Heatmap HM(opts::HeatmapBlock, opts::HeatmapMinAddress,
1295-
opts::HeatmapMaxAddress);
1311+
opts::HeatmapMaxAddress, getTextSections(BC));
12961312
uint64_t NumTotalSamples = 0;
12971313

12981314
if (opts::BasicAggregation) {
@@ -1374,6 +1390,10 @@ std::error_code DataAggregator::printLBRHeatMap() {
13741390
HM.printCDF(opts::OutputFilename);
13751391
else
13761392
HM.printCDF(opts::OutputFilename + ".csv");
1393+
if (opts::OutputFilename == "-")
1394+
HM.printSectionHotness(opts::OutputFilename);
1395+
else
1396+
HM.printSectionHotness(opts::OutputFilename + "-section-hotness.csv");
13771397

13781398
return std::error_code();
13791399
}

bolt/lib/Profile/Heatmap.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "bolt/Profile/Heatmap.h"
1010
#include "bolt/Utils/CommandLineOpts.h"
11+
#include "llvm/ADT/StringMap.h"
1112
#include "llvm/ADT/Twine.h"
1213
#include "llvm/Support/CommandLine.h"
1314
#include "llvm/Support/Debug.h"
@@ -251,5 +252,64 @@ void Heatmap::printCDF(raw_ostream &OS) const {
251252
Counts.clear();
252253
}
253254

255+
void Heatmap::printSectionHotness(StringRef FileName) const {
256+
std::error_code EC;
257+
raw_fd_ostream OS(FileName, EC, sys::fs::OpenFlags::OF_None);
258+
if (EC) {
259+
errs() << "error opening output file: " << EC.message() << '\n';
260+
exit(1);
261+
}
262+
printSectionHotness(OS);
263+
}
264+
265+
void Heatmap::printSectionHotness(raw_ostream &OS) const {
266+
uint64_t NumTotalCounts = 0;
267+
StringMap<uint64_t> SectionHotness;
268+
unsigned TextSectionIndex = 0;
269+
270+
if (TextSections.empty())
271+
return;
272+
273+
uint64_t UnmappedHotness = 0;
274+
auto RecordUnmappedBucket = [&](uint64_t Address, uint64_t Frequency) {
275+
errs() << "Couldn't map the address bucket [0x" << Twine::utohexstr(Address)
276+
<< ", 0x" << Twine::utohexstr(Address + BucketSize)
277+
<< "] containing " << Frequency
278+
<< " samples to a text section in the binary.";
279+
UnmappedHotness += Frequency;
280+
};
281+
282+
for (const std::pair<const uint64_t, uint64_t> &KV : Map) {
283+
NumTotalCounts += KV.second;
284+
// We map an address bucket to the first section (lowest address)
285+
// overlapping with that bucket.
286+
auto Address = KV.first * BucketSize;
287+
while (TextSectionIndex < TextSections.size() &&
288+
Address >= TextSections[TextSectionIndex].EndAddress)
289+
TextSectionIndex++;
290+
if (TextSectionIndex >= TextSections.size() ||
291+
Address + BucketSize < TextSections[TextSectionIndex].BeginAddress) {
292+
RecordUnmappedBucket(Address, KV.second);
293+
continue;
294+
}
295+
SectionHotness[TextSections[TextSectionIndex].Name] += KV.second;
296+
}
297+
298+
assert(NumTotalCounts > 0 &&
299+
"total number of heatmap buckets should be greater than 0");
300+
301+
OS << "Section Name, Begin Address, End Address, Percentage Hotness\n";
302+
for (auto &TextSection : TextSections) {
303+
OS << TextSection.Name << ", 0x"
304+
<< Twine::utohexstr(TextSection.BeginAddress) << ", 0x"
305+
<< Twine::utohexstr(TextSection.EndAddress) << ", "
306+
<< format("%.4f",
307+
100.0 * SectionHotness[TextSection.Name] / NumTotalCounts)
308+
<< "\n";
309+
}
310+
if (UnmappedHotness > 0)
311+
OS << "[unmapped], 0x0, 0x0, "
312+
<< format("%.4f", 100.0 * UnmappedHotness / NumTotalCounts) << "\n";
313+
}
254314
} // namespace bolt
255315
} // namespace llvm

clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ class HeaderGuardPPCallbacks : public PPCallbacks {
145145
EndIfStr[FindEscapedNewline] == '\\')
146146
return false;
147147

148-
if (!Check->shouldSuggestEndifComment(FileName) &&
149-
!(EndIfStr.startswith("//") ||
150-
(EndIfStr.startswith("/*") && EndIfStr.endswith("*/"))))
151-
return false;
148+
bool IsLineComment =
149+
EndIfStr.consume_front("//") ||
150+
(EndIfStr.consume_front("/*") && EndIfStr.consume_back("*/"));
151+
if (!IsLineComment)
152+
return Check->shouldSuggestEndifComment(FileName);
152153

153-
return (EndIfStr != "// " + HeaderGuard.str()) &&
154-
(EndIfStr != "/* " + HeaderGuard.str() + " */");
154+
return EndIfStr.trim() != HeaderGuard;
155155
}
156156

157157
/// Look for header guards that don't match the preferred style. Emit

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,10 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
258258
bool VisitFunctionDecl(FunctionDecl *D) {
259259
if (auto *FPT =
260260
llvm::dyn_cast<FunctionProtoType>(D->getType().getTypePtr())) {
261-
if (!FPT->hasTrailingReturn())
262-
addReturnTypeHint(D, D->getFunctionTypeLoc().getRParenLoc());
261+
if (!FPT->hasTrailingReturn()) {
262+
if (auto FTL = D->getFunctionTypeLoc())
263+
addReturnTypeHint(D, FTL.getRParenLoc());
264+
}
263265
}
264266
return true;
265267
}

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,16 @@ TEST(TypeHints, SinglyInstantiatedTemplate) {
811811
ExpectedHint{": void *", "a"});
812812
}
813813

814+
TEST(TypeHints, Aliased) {
815+
// Check that we don't crash for functions without a FunctionTypeLoc.
816+
// https://github.com/clangd/clangd/issues/1140
817+
TestTU TU = TestTU::withCode("void foo(void){} extern typeof(foo) foo;");
818+
TU.ExtraArgs.push_back("-xc");
819+
auto AST = TU.build();
820+
821+
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::TypeHint), IsEmpty());
822+
}
823+
814824
TEST(DesignatorHints, Basic) {
815825
assertDesignatorHints(R"cpp(
816826
struct S { int x, y, z; };

clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) {
204204
"include/llvm/ADT/foo.h",
205205
StringRef("header guard does not follow preferred style")));
206206

207+
// An extra space inside the comment is OK.
208+
llvm::StringRef WithExtraSpace = "#ifndef LLVM_ADT_FOO_H\n"
209+
"#define LLVM_ADT_FOO_H\n"
210+
"#endif // LLVM_ADT_FOO_H\n";
211+
EXPECT_EQ(WithExtraSpace,
212+
runHeaderGuardCheckWithEndif(WithExtraSpace,
213+
"include/llvm/ADT/foo.h", None));
214+
207215
EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n"
208216
"#define LLVM_ADT_FOO_H\n"
209217
"#endif \\ \n"

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4019,7 +4019,7 @@ Note that ``-ffp-contract=fast`` will override pragmas to fuse multiply and
40194019
addition across statements regardless of any controlling pragmas.
40204020
40214021
``#pragma clang fp exceptions`` specifies floating point exception behavior. It
4022-
may take one the the values: ``ignore``, ``maytrap`` or ``strict``. Meaning of
4022+
may take one of the values: ``ignore``, ``maytrap`` or ``strict``. Meaning of
40234023
these values is same as for `constrained floating point intrinsics <http://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics>`_.
40244024
40254025
.. code-block:: c++

clang/docs/MatrixTypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Definitions:
208208
``M2 __builtin_matrix_transpose(M1 matrix)``
209209

210210
**Remarks**: The return type is a cv-unqualified matrix type that has the same
211-
element type as ``M1`` and has the the same number of rows as ``M1`` has columns and
211+
element type as ``M1`` and has the same number of rows as ``M1`` has columns and
212212
the same number of columns as ``M1`` has rows.
213213

214214
**Returns**: A matrix ``Res`` equivalent to the code below, where ``col`` refers to the

0 commit comments

Comments
 (0)