Skip to content

Commit 6d25537

Browse files
authored
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_binding_to_temporary
2 parents 016d341 + ec9c293 commit 6d25537

File tree

383 files changed

+12846
-6976
lines changed

Some content is hidden

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

383 files changed

+12846
-6976
lines changed

.github/workflows/release-binaries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
# 2-3 hours to build on macOS, much slower than on Linux.
143143
# The long build time causes the release build to time out on x86_64,
144144
# so we need to disable flang there.
145-
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;bolt;polly;mlir'"
145+
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
146146
fi
147147
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_BOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
148148
fi

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bolt/Core/DynoStats.h"
1616
#include "bolt/Core/HashUtilities.h"
1717
#include "bolt/Core/MCPlusBuilder.h"
18+
#include "bolt/Utils/CommandLineOpts.h"
1819
#include "bolt/Utils/NameResolver.h"
1920
#include "bolt/Utils/NameShortener.h"
2021
#include "bolt/Utils/Utils.h"
@@ -1753,8 +1754,8 @@ void BinaryFunction::postProcessEntryPoints() {
17531754
// In non-relocation mode there's potentially an external undetectable
17541755
// reference to the entry point and hence we cannot move this entry
17551756
// point. Optimizing without moving could be difficult.
1756-
// In BAT mode, register any known entry points for CFG construction.
1757-
if (!BC.HasRelocations && !BC.HasBATSection)
1757+
// In aggregation, register any known entry points for CFG construction.
1758+
if (!BC.HasRelocations && !opts::AggregateOnly)
17581759
setSimple(false);
17591760

17601761
const uint32_t Offset = KV.first;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,10 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
831831
ParentFunc = FromFunc;
832832
ParentFunc->SampleCountInBytes += Count * (Second.From - First.To);
833833

834+
const uint64_t FuncAddress = FromFunc->getAddress();
834835
std::optional<BoltAddressTranslation::FallthroughListTy> FTs =
835-
BAT ? BAT->getFallthroughsInTrace(FromFunc->getAddress(), First.To,
836-
Second.From)
836+
BAT && BAT->isBATFunction(FuncAddress)
837+
? BAT->getFallthroughsInTrace(FuncAddress, First.To, Second.From)
837838
: getFallthroughsInTrace(*FromFunc, First, Second, Count);
838839
if (!FTs) {
839840
LLVM_DEBUG(

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ YAML-BAT-CHECK-NEXT: - bid: 0
6161
YAML-BAT-CHECK-NEXT: insns: 26
6262
YAML-BAT-CHECK-NEXT: hash: 0xA900AE79CFD40000
6363
YAML-BAT-CHECK-NEXT: succ: [ { bid: 3, cnt: 0 }, { bid: 1, cnt: 0 } ]
64+
# Check fallthroughs in non-BAT function
65+
YAML-BAT-CHECK-NEXT: - bid: 27
66+
YAML-BAT-CHECK-NEXT: insns: 3
67+
YAML-BAT-CHECK-NEXT: hash: 0x30A1EBA77A903F0
68+
YAML-BAT-CHECK-NEXT: succ: [ { bid: 28, cnt: 1 } ]
6469
# Calls from no-BAT to BAT function
6570
YAML-BAT-CHECK: - bid: 28
6671
YAML-BAT-CHECK-NEXT: insns: 13
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Checks that fallthroughs spanning entry points are accepted in aggregation
2+
## mode.
3+
4+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
5+
# RUN: ld.lld %t.o -o %t
6+
# RUN: link_fdata %s %t %t.preagg PREAGG
7+
# RUN: perf2bolt %t -p %t.preagg --pa -o %t.fdata | FileCheck %s
8+
# CHECK: traces mismatching disassembled function contents: 0
9+
10+
.globl main
11+
main:
12+
.cfi_startproc
13+
vmovaps %zmm31,%zmm3
14+
15+
next:
16+
add $0x4,%r9
17+
add $0x40,%r10
18+
dec %r14
19+
Ljmp:
20+
jne main
21+
# PREAGG: T #Ljmp# #main# #Ljmp# 1
22+
ret
23+
.cfi_endproc
24+
.size main,.-main

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,89 @@ void ModuleFileCache::remove(StringRef ModuleName) {
357357
ModuleFiles.erase(ModuleName);
358358
}
359359

360+
class ModuleNameToSourceCache {
361+
public:
362+
std::string getSourceForModuleName(llvm::StringRef ModuleName) {
363+
std::lock_guard<std::mutex> Lock(CacheMutex);
364+
auto Iter = ModuleNameToSourceCache.find(ModuleName);
365+
if (Iter != ModuleNameToSourceCache.end())
366+
return Iter->second;
367+
return "";
368+
}
369+
370+
void addEntry(llvm::StringRef ModuleName, PathRef Source) {
371+
std::lock_guard<std::mutex> Lock(CacheMutex);
372+
ModuleNameToSourceCache[ModuleName] = Source.str();
373+
}
374+
375+
void eraseEntry(llvm::StringRef ModuleName) {
376+
std::lock_guard<std::mutex> Lock(CacheMutex);
377+
ModuleNameToSourceCache.erase(ModuleName);
378+
}
379+
380+
private:
381+
std::mutex CacheMutex;
382+
llvm::StringMap<std::string> ModuleNameToSourceCache;
383+
};
384+
385+
class CachingProjectModules : public ProjectModules {
386+
public:
387+
CachingProjectModules(std::unique_ptr<ProjectModules> MDB,
388+
ModuleNameToSourceCache &Cache)
389+
: MDB(std::move(MDB)), Cache(Cache) {
390+
assert(this->MDB && "CachingProjectModules should only be created with a "
391+
"valid underlying ProjectModules");
392+
}
393+
394+
std::vector<std::string> getRequiredModules(PathRef File) override {
395+
return MDB->getRequiredModules(File);
396+
}
397+
398+
std::string getModuleNameForSource(PathRef File) override {
399+
return MDB->getModuleNameForSource(File);
400+
}
401+
402+
std::string getSourceForModuleName(llvm::StringRef ModuleName,
403+
PathRef RequiredSrcFile) override {
404+
std::string CachedResult = Cache.getSourceForModuleName(ModuleName);
405+
406+
// Verify Cached Result by seeing if the source declaring the same module
407+
// as we query.
408+
if (!CachedResult.empty()) {
409+
std::string ModuleNameOfCachedSource =
410+
MDB->getModuleNameForSource(CachedResult);
411+
if (ModuleNameOfCachedSource == ModuleName)
412+
return CachedResult;
413+
414+
// Cached Result is invalid. Clear it.
415+
Cache.eraseEntry(ModuleName);
416+
}
417+
418+
auto Result = MDB->getSourceForModuleName(ModuleName, RequiredSrcFile);
419+
Cache.addEntry(ModuleName, Result);
420+
421+
return Result;
422+
}
423+
424+
private:
425+
std::unique_ptr<ProjectModules> MDB;
426+
ModuleNameToSourceCache &Cache;
427+
};
428+
360429
/// Collect the directly and indirectly required module names for \param
361430
/// ModuleName in topological order. The \param ModuleName is guaranteed to
362431
/// be the last element in \param ModuleNames.
363-
llvm::SmallVector<StringRef> getAllRequiredModules(ProjectModules &MDB,
432+
llvm::SmallVector<StringRef> getAllRequiredModules(PathRef RequiredSource,
433+
CachingProjectModules &MDB,
364434
StringRef ModuleName) {
365435
llvm::SmallVector<llvm::StringRef> ModuleNames;
366436
llvm::StringSet<> ModuleNamesSet;
367437

368438
auto VisitDeps = [&](StringRef ModuleName, auto Visitor) -> void {
369439
ModuleNamesSet.insert(ModuleName);
370440

371-
for (StringRef RequiredModuleName :
372-
MDB.getRequiredModules(MDB.getSourceForModuleName(ModuleName)))
441+
for (StringRef RequiredModuleName : MDB.getRequiredModules(
442+
MDB.getSourceForModuleName(ModuleName, RequiredSource)))
373443
if (ModuleNamesSet.insert(RequiredModuleName).second)
374444
Visitor(RequiredModuleName, Visitor);
375445

@@ -386,24 +456,29 @@ class ModulesBuilder::ModulesBuilderImpl {
386456
public:
387457
ModulesBuilderImpl(const GlobalCompilationDatabase &CDB) : Cache(CDB) {}
388458

459+
ModuleNameToSourceCache &getProjectModulesCache() {
460+
return ProjectModulesCache;
461+
}
389462
const GlobalCompilationDatabase &getCDB() const { return Cache.getCDB(); }
390463

391464
llvm::Error
392-
getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
393-
ProjectModules &MDB,
465+
getOrBuildModuleFile(PathRef RequiredSource, StringRef ModuleName,
466+
const ThreadsafeFS &TFS, CachingProjectModules &MDB,
394467
ReusablePrerequisiteModules &BuiltModuleFiles);
395468

396469
private:
397470
ModuleFileCache Cache;
471+
ModuleNameToSourceCache ProjectModulesCache;
398472
};
399473

400474
llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
401-
StringRef ModuleName, const ThreadsafeFS &TFS, ProjectModules &MDB,
402-
ReusablePrerequisiteModules &BuiltModuleFiles) {
475+
PathRef RequiredSource, StringRef ModuleName, const ThreadsafeFS &TFS,
476+
CachingProjectModules &MDB, ReusablePrerequisiteModules &BuiltModuleFiles) {
403477
if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName))
404478
return llvm::Error::success();
405479

406-
PathRef ModuleUnitFileName = MDB.getSourceForModuleName(ModuleName);
480+
std::string ModuleUnitFileName =
481+
MDB.getSourceForModuleName(ModuleName, RequiredSource);
407482
/// It is possible that we're meeting third party modules (modules whose
408483
/// source are not in the project. e.g, the std module may be a third-party
409484
/// module for most project) or something wrong with the implementation of
@@ -416,7 +491,7 @@ llvm::Error ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile(
416491
llvm::formatv("Don't get the module unit for module {0}", ModuleName));
417492

418493
// Get Required modules in topological order.
419-
auto ReqModuleNames = getAllRequiredModules(MDB, ModuleName);
494+
auto ReqModuleNames = getAllRequiredModules(RequiredSource, MDB, ModuleName);
420495
for (llvm::StringRef ReqModuleName : ReqModuleNames) {
421496
if (BuiltModuleFiles.isModuleUnitBuilt(ModuleName))
422497
continue;
@@ -454,16 +529,19 @@ ModulesBuilder::buildPrerequisiteModulesFor(PathRef File,
454529
elog("Failed to get Project Modules information for {0}", File);
455530
return std::make_unique<FailedPrerequisiteModules>();
456531
}
532+
CachingProjectModules CachedMDB(std::move(MDB),
533+
Impl->getProjectModulesCache());
457534

458-
std::vector<std::string> RequiredModuleNames = MDB->getRequiredModules(File);
535+
std::vector<std::string> RequiredModuleNames =
536+
CachedMDB.getRequiredModules(File);
459537
if (RequiredModuleNames.empty())
460538
return std::make_unique<ReusablePrerequisiteModules>();
461539

462540
auto RequiredModules = std::make_unique<ReusablePrerequisiteModules>();
463541
for (llvm::StringRef RequiredModuleName : RequiredModuleNames) {
464542
// Return early if there is any error.
465543
if (llvm::Error Err = Impl->getOrBuildModuleFile(
466-
RequiredModuleName, TFS, *MDB.get(), *RequiredModules.get())) {
544+
File, RequiredModuleName, TFS, CachedMDB, *RequiredModules.get())) {
467545
elog("Failed to build module {0}; due to {1}", RequiredModuleName,
468546
toString(std::move(Err)));
469547
return std::make_unique<FailedPrerequisiteModules>();

clang-tools-extra/clangd/ProjectModules.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class ProjectModules {
4242
llvm::unique_function<void(tooling::CompileCommand &, PathRef) const>;
4343

4444
virtual std::vector<std::string> getRequiredModules(PathRef File) = 0;
45-
virtual PathRef
46-
getSourceForModuleName(llvm::StringRef ModuleName,
47-
PathRef RequiredSrcFile = PathRef()) = 0;
45+
virtual std::string getModuleNameForSource(PathRef File) = 0;
46+
virtual std::string getSourceForModuleName(llvm::StringRef ModuleName,
47+
PathRef RequiredSrcFile) = 0;
4848

4949
virtual void setCommandMangler(CommandMangler Mangler) {}
5050

clang-tools-extra/clangd/ScanningProjectModules.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ ModuleDependencyScanner::scan(PathRef FilePath,
134134

135135
void ModuleDependencyScanner::globalScan(
136136
const ProjectModules::CommandMangler &Mangler) {
137+
if (GlobalScanned)
138+
return;
139+
137140
for (auto &File : CDB->getAllFiles())
138141
scan(File, Mangler);
139142

@@ -189,11 +192,18 @@ class ScanningAllProjectModules : public ProjectModules {
189192

190193
/// RequiredSourceFile is not used intentionally. See the comments of
191194
/// ModuleDependencyScanner for detail.
192-
PathRef
193-
getSourceForModuleName(llvm::StringRef ModuleName,
194-
PathRef RequiredSourceFile = PathRef()) override {
195+
std::string getSourceForModuleName(llvm::StringRef ModuleName,
196+
PathRef RequiredSourceFile) override {
195197
Scanner.globalScan(Mangler);
196-
return Scanner.getSourceForModuleName(ModuleName);
198+
return Scanner.getSourceForModuleName(ModuleName).str();
199+
}
200+
201+
std::string getModuleNameForSource(PathRef File) override {
202+
auto ScanningResult = Scanner.scan(File, Mangler);
203+
if (!ScanningResult || !ScanningResult->ModuleName)
204+
return {};
205+
206+
return *ScanningResult->ModuleName;
197207
}
198208

199209
private:

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

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,54 @@
2727
namespace clang::clangd {
2828
namespace {
2929

30+
class GlobalScanningCounterProjectModules : public ProjectModules {
31+
public:
32+
GlobalScanningCounterProjectModules(
33+
std::unique_ptr<ProjectModules> Underlying, std::atomic<unsigned> &Count)
34+
: Underlying(std::move(Underlying)), Count(Count) {}
35+
36+
std::vector<std::string> getRequiredModules(PathRef File) override {
37+
return Underlying->getRequiredModules(File);
38+
}
39+
40+
std::string getModuleNameForSource(PathRef File) override {
41+
return Underlying->getModuleNameForSource(File);
42+
}
43+
44+
void setCommandMangler(CommandMangler Mangler) override {
45+
Underlying->setCommandMangler(std::move(Mangler));
46+
}
47+
48+
std::string getSourceForModuleName(llvm::StringRef ModuleName,
49+
PathRef RequiredSrcFile) override {
50+
Count++;
51+
return Underlying->getSourceForModuleName(ModuleName, RequiredSrcFile);
52+
}
53+
54+
private:
55+
std::unique_ptr<ProjectModules> Underlying;
56+
std::atomic<unsigned> &Count;
57+
};
58+
3059
class MockDirectoryCompilationDatabase : public MockCompilationDatabase {
3160
public:
3261
MockDirectoryCompilationDatabase(StringRef TestDir, const ThreadsafeFS &TFS)
3362
: MockCompilationDatabase(TestDir),
3463
MockedCDBPtr(std::make_shared<MockClangCompilationDatabase>(*this)),
35-
TFS(TFS) {
64+
TFS(TFS), GlobalScanningCount(0) {
3665
this->ExtraClangFlags.push_back("-std=c++20");
3766
this->ExtraClangFlags.push_back("-c");
3867
}
3968

4069
void addFile(llvm::StringRef Path, llvm::StringRef Contents);
4170

4271
std::unique_ptr<ProjectModules> getProjectModules(PathRef) const override {
43-
return scanningProjectModules(MockedCDBPtr, TFS);
72+
return std::make_unique<GlobalScanningCounterProjectModules>(
73+
scanningProjectModules(MockedCDBPtr, TFS), GlobalScanningCount);
4474
}
4575

76+
unsigned getGlobalScanningCount() const { return GlobalScanningCount; }
77+
4678
private:
4779
class MockClangCompilationDatabase : public tooling::CompilationDatabase {
4880
public:
@@ -68,6 +100,8 @@ class MockDirectoryCompilationDatabase : public MockCompilationDatabase {
68100

69101
std::shared_ptr<MockClangCompilationDatabase> MockedCDBPtr;
70102
const ThreadsafeFS &TFS;
103+
104+
mutable std::atomic<unsigned> GlobalScanningCount;
71105
};
72106

73107
// Add files to the working testing directory and the compilation database.
@@ -590,6 +624,28 @@ export constexpr int M = 43;
590624
EXPECT_NE(NewHSOptsA.PrebuiltModuleFiles, HSOptsA.PrebuiltModuleFiles);
591625
}
592626

627+
TEST_F(PrerequisiteModulesTests, ScanningCacheTest) {
628+
MockDirectoryCompilationDatabase CDB(TestDir, FS);
629+
630+
CDB.addFile("M.cppm", R"cpp(
631+
export module M;
632+
)cpp");
633+
CDB.addFile("A.cppm", R"cpp(
634+
export module A;
635+
import M;
636+
)cpp");
637+
CDB.addFile("B.cppm", R"cpp(
638+
export module B;
639+
import M;
640+
)cpp");
641+
642+
ModulesBuilder Builder(CDB);
643+
644+
Builder.buildPrerequisiteModulesFor(getFullPath("A.cppm"), FS);
645+
Builder.buildPrerequisiteModulesFor(getFullPath("B.cppm"), FS);
646+
EXPECT_EQ(CDB.getGlobalScanningCount(), 1u);
647+
}
648+
593649
} // namespace
594650
} // namespace clang::clangd
595651

clang/Maintainers.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Clang static analyzer
136136
137137
| Balázs Benics
138138
| benicsbalazs\@gmail.com (email), steakhal (Phabricator), steakhal (GitHub)
139+
| balazs.benics\@sonarsource.com (email), balazs-benics-sonarsource (GitHub)
139140
140141
Compiler options
141142
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)