Skip to content

Commit 2849685

Browse files
Merge branch 'main' into get-huge-money
2 parents 61775dc + e3f5269 commit 2849685

File tree

1,276 files changed

+50250
-27969
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,276 files changed

+50250
-27969
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/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "UnnecessaryValueParamCheck.h"
10-
1110
#include "../utils/DeclRefExprUtils.h"
1211
#include "../utils/FixItHintUtils.h"
1312
#include "../utils/Matchers.h"
@@ -30,14 +29,6 @@ std::string paramNameOrIndex(StringRef Name, size_t Index) {
3029
.str();
3130
}
3231

33-
bool isReferencedOutsideOfCallExpr(const FunctionDecl &Function,
34-
ASTContext &Context) {
35-
auto Matches = match(declRefExpr(to(functionDecl(equalsNode(&Function))),
36-
unless(hasAncestor(callExpr()))),
37-
Context);
38-
return !Matches.empty();
39-
}
40-
4132
bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
4233
ASTContext &Context) {
4334
auto Matches = match(
@@ -155,12 +146,9 @@ void UnnecessaryValueParamCheck::handleConstRefFix(const FunctionDecl &Function,
155146
// Do not propose fixes when:
156147
// 1. the ParmVarDecl is in a macro, since we cannot place them correctly
157148
// 2. the function is virtual as it might break overrides
158-
// 3. the function is referenced outside of a call expression within the
159-
// compilation unit as the signature change could introduce build errors.
160-
// 4. the function is an explicit template/ specialization.
149+
// 3. the function is an explicit template/ specialization.
161150
const auto *Method = llvm::dyn_cast<CXXMethodDecl>(&Function);
162151
if (Param.getBeginLoc().isMacroID() || (Method && Method->isVirtual()) ||
163-
isReferencedOutsideOfCallExpr(Function, Context) ||
164152
Function.getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
165153
return;
166154
for (const auto *FunctionDecl = &Function; FunctionDecl != nullptr;

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:

0 commit comments

Comments
 (0)