Skip to content

Commit cdba2c5

Browse files
authored
Merge branch 'main' into wchar-wcrtomb
2 parents edf8aea + b6445ac commit cdba2c5

File tree

133 files changed

+7122
-4731
lines changed

Some content is hidden

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

133 files changed

+7122
-4731
lines changed

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress,
546546
return Res;
547547

548548
for (auto Iter = FromIter; Iter != ToIter;) {
549-
const uint32_t Src = Iter->first;
549+
const uint32_t Src = Iter->second >> 1;
550550
if (Iter->second & BRANCHENTRY) {
551551
++Iter;
552552
continue;
@@ -557,7 +557,7 @@ BoltAddressTranslation::getFallthroughsInTrace(uint64_t FuncAddress,
557557
++Iter;
558558
if (Iter->second & BRANCHENTRY)
559559
break;
560-
Res.emplace_back(Src, Iter->first);
560+
Res.emplace_back(Src, Iter->second >> 1);
561561
}
562562

563563
return Res;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,8 @@ bool DataAggregator::doTrace(const Trace &Trace, uint64_t Count,
835835

836836
LLVM_DEBUG(dbgs() << "Processing " << FTs->size() << " fallthroughs for "
837837
<< FromFunc->getPrintName() << ":" << Trace << '\n');
838-
for (auto [From, To] : *FTs) {
839-
if (BAT) {
840-
From = BAT->translate(FromFunc->getAddress(), From, /*IsBranchSrc=*/true);
841-
To = BAT->translate(FromFunc->getAddress(), To, /*IsBranchSrc=*/false);
842-
}
838+
for (const auto &[From, To] : *FTs)
843839
doIntraBranch(*ParentFunc, From, To, Count, false);
844-
}
845840

846841
return true;
847842
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,11 @@ void RewriteInstance::registerFragments() {
15671567

15681568
uint64_t ParentAddress{0};
15691569

1570+
// Check if containing FILE symbol is BOLT emitted synthetic symbol marking
1571+
// local fragments of global parents.
1572+
if (cantFail(FSI[-1].getName()) == getBOLTFileSymbolName())
1573+
goto registerParent;
1574+
15701575
// BOLT split fragment symbols are emitted just before the main function
15711576
// symbol.
15721577
for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;

bolt/test/X86/register-fragments-bolt-symbols.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
3131
# PREAGG: B X:0 #chain.cold.0# 1 0
32+
# PREAGG: B X:0 #dummy# 1 0
3233
# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 \
3334
# RUN: | FileCheck %s --check-prefix=CHECK-REGISTER
3435
# RUN: FileCheck --input-file %t.bat.fdata --check-prefix=CHECK-FDATA %s
@@ -44,7 +45,13 @@
4445
# CHECK-SYMS: l F .text.cold [[#]] chain.cold.0
4546
# CHECK-SYMS: l F .text [[#]] chain
4647
# CHECK-SYMS: l df *ABS* [[#]] bolt-pseudo.o
48+
# CHECK-SYMS: l F .text.cold [[#]] dummy.cold.0
49+
# CHECK-SYMS: l F .text.cold.1 [[#]] dummy.cold.1
50+
# CHECK-SYMS: l F .text.cold.2 [[#]] dummy.cold.2
4751

52+
# CHECK-REGISTER: BOLT-INFO: marking dummy.cold.0/1(*2) as a fragment of dummy
53+
# CHECK-REGISTER: BOLT-INFO: marking dummy.cold.1/1(*2) as a fragment of dummy
54+
# CHECK-REGISTER: BOLT-INFO: marking dummy.cold.2/1(*2) as a fragment of dummy
4855
# CHECK-REGISTER: BOLT-INFO: marking chain.cold.0/1(*2) as a fragment of chain/2(*2)
4956

5057
# CHECK-FDATA: 0 [unknown] 0 1 chain/chain.s/2 10 0 1

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace clang {
2323
namespace tooling {
2424
namespace dependencies {
2525

26+
class DependencyScanningService;
27+
2628
using DependencyDirectivesTy =
2729
SmallVector<dependency_directives_scan::Directive, 20>;
2830

@@ -349,7 +351,7 @@ class DependencyScanningWorkerFilesystem
349351
static const char ID;
350352

351353
DependencyScanningWorkerFilesystem(
352-
DependencyScanningFilesystemSharedCache &SharedCache,
354+
DependencyScanningService &Service,
353355
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
354356

355357
llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override;
@@ -435,10 +437,7 @@ class DependencyScanningWorkerFilesystem
435437
/// Returns entry associated with the unique ID in the shared cache or nullptr
436438
/// if none is found.
437439
const CachedFileSystemEntry *
438-
findSharedEntryByUID(llvm::vfs::Status Stat) const {
439-
return SharedCache.getShardForUID(Stat.getUniqueID())
440-
.findEntryByUID(Stat.getUniqueID());
441-
}
440+
findSharedEntryByUID(llvm::vfs::Status Stat) const;
442441

443442
/// Associates the given entry with the filename in the local cache and
444443
/// returns it.
@@ -452,20 +451,14 @@ class DependencyScanningWorkerFilesystem
452451
/// some. Otherwise, constructs new one with the given error code, associates
453452
/// it with the filename and returns the result.
454453
const CachedFileSystemEntry &
455-
getOrEmplaceSharedEntryForFilename(StringRef Filename, std::error_code EC) {
456-
return SharedCache.getShardForFilename(Filename)
457-
.getOrEmplaceEntryForFilename(Filename, EC);
458-
}
454+
getOrEmplaceSharedEntryForFilename(StringRef Filename, std::error_code EC);
459455

460456
/// Returns entry associated with the filename in the shared cache if there is
461457
/// some. Otherwise, associates the given entry with the filename and returns
462458
/// it.
463459
const CachedFileSystemEntry &
464460
getOrInsertSharedEntryForFilename(StringRef Filename,
465-
const CachedFileSystemEntry &Entry) {
466-
return SharedCache.getShardForFilename(Filename)
467-
.getOrInsertEntryForFilename(Filename, Entry);
468-
}
461+
const CachedFileSystemEntry &Entry);
469462

470463
void printImpl(raw_ostream &OS, PrintType Type,
471464
unsigned IndentLevel) const override {
@@ -478,8 +471,9 @@ class DependencyScanningWorkerFilesystem
478471
/// VFS.
479472
bool shouldBypass(StringRef Path) const;
480473

481-
/// The global cache shared between worker threads.
482-
DependencyScanningFilesystemSharedCache &SharedCache;
474+
/// The service associated with this VFS.
475+
DependencyScanningService &Service;
476+
483477
/// The local cache is used by the worker thread to cache file system queries
484478
/// locally instead of querying the global cache every time.
485479
DependencyScanningFilesystemLocalCache LocalCache;

clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class DependencyScanningService {
8787
ScanningOptimizations OptimizeArgs = ScanningOptimizations::Default,
8888
bool EagerLoadModules = false, bool TraceVFS = false,
8989
std::time_t BuildSessionTimestamp =
90-
llvm::sys::toTimeT(std::chrono::system_clock::now()));
90+
llvm::sys::toTimeT(std::chrono::system_clock::now()),
91+
bool CacheNegativeStats = true);
9192

9293
ScanningMode getMode() const { return Mode; }
9394

@@ -99,6 +100,8 @@ class DependencyScanningService {
99100

100101
bool shouldTraceVFS() const { return TraceVFS; }
101102

103+
bool shouldCacheNegativeStats() const { return CacheNegativeStats; }
104+
102105
DependencyScanningFilesystemSharedCache &getSharedCache() {
103106
return SharedCache;
104107
}
@@ -116,6 +119,7 @@ class DependencyScanningService {
116119
const bool EagerLoadModules;
117120
/// Whether to trace VFS accesses.
118121
const bool TraceVFS;
122+
const bool CacheNegativeStats;
119123
/// The global file system cache.
120124
DependencyScanningFilesystemSharedCache SharedCache;
121125
/// The global module cache entries.

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

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

99
#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
10+
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
1011
#include "llvm/Support/MemoryBuffer.h"
1112
#include "llvm/Support/Threading.h"
1213
#include <optional>
@@ -232,19 +233,19 @@ bool DependencyScanningWorkerFilesystem::shouldBypass(StringRef Path) const {
232233
}
233234

234235
DependencyScanningWorkerFilesystem::DependencyScanningWorkerFilesystem(
235-
DependencyScanningFilesystemSharedCache &SharedCache,
236+
DependencyScanningService &Service,
236237
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
237238
: llvm::RTTIExtends<DependencyScanningWorkerFilesystem,
238239
llvm::vfs::ProxyFileSystem>(std::move(FS)),
239-
SharedCache(SharedCache),
240-
WorkingDirForCacheLookup(llvm::errc::invalid_argument) {
240+
Service(Service), WorkingDirForCacheLookup(llvm::errc::invalid_argument) {
241241
updateWorkingDirForCacheLookup();
242242
}
243243

244244
const CachedFileSystemEntry &
245245
DependencyScanningWorkerFilesystem::getOrEmplaceSharedEntryForUID(
246246
TentativeEntry TEntry) {
247-
auto &Shard = SharedCache.getShardForUID(TEntry.Status.getUniqueID());
247+
auto &Shard =
248+
Service.getSharedCache().getShardForUID(TEntry.Status.getUniqueID());
248249
return Shard.getOrEmplaceEntryForUID(TEntry.Status.getUniqueID(),
249250
std::move(TEntry.Status),
250251
std::move(TEntry.Contents));
@@ -255,18 +256,44 @@ DependencyScanningWorkerFilesystem::findEntryByFilenameWithWriteThrough(
255256
StringRef Filename) {
256257
if (const auto *Entry = LocalCache.findEntryByFilename(Filename))
257258
return Entry;
258-
auto &Shard = SharedCache.getShardForFilename(Filename);
259+
auto &Shard = Service.getSharedCache().getShardForFilename(Filename);
259260
if (const auto *Entry = Shard.findEntryByFilename(Filename))
260261
return &LocalCache.insertEntryForFilename(Filename, *Entry);
261262
return nullptr;
262263
}
263264

265+
const CachedFileSystemEntry *
266+
DependencyScanningWorkerFilesystem::findSharedEntryByUID(
267+
llvm::vfs::Status Stat) const {
268+
return Service.getSharedCache()
269+
.getShardForUID(Stat.getUniqueID())
270+
.findEntryByUID(Stat.getUniqueID());
271+
}
272+
273+
const CachedFileSystemEntry &
274+
DependencyScanningWorkerFilesystem::getOrEmplaceSharedEntryForFilename(
275+
StringRef Filename, std::error_code EC) {
276+
return Service.getSharedCache()
277+
.getShardForFilename(Filename)
278+
.getOrEmplaceEntryForFilename(Filename, EC);
279+
}
280+
281+
const CachedFileSystemEntry &
282+
DependencyScanningWorkerFilesystem::getOrInsertSharedEntryForFilename(
283+
StringRef Filename, const CachedFileSystemEntry &Entry) {
284+
return Service.getSharedCache()
285+
.getShardForFilename(Filename)
286+
.getOrInsertEntryForFilename(Filename, Entry);
287+
}
288+
264289
llvm::ErrorOr<const CachedFileSystemEntry &>
265290
DependencyScanningWorkerFilesystem::computeAndStoreResult(
266291
StringRef OriginalFilename, StringRef FilenameForLookup) {
267292
llvm::ErrorOr<llvm::vfs::Status> Stat =
268293
getUnderlyingFS().status(OriginalFilename);
269294
if (!Stat) {
295+
if (!Service.shouldCacheNegativeStats())
296+
return Stat.getError();
270297
const auto &Entry =
271298
getOrEmplaceSharedEntryForFilename(FilenameForLookup, Stat.getError());
272299
return insertLocalEntryForFilename(FilenameForLookup, Entry);
@@ -420,7 +447,8 @@ DependencyScanningWorkerFilesystem::getRealPath(const Twine &Path,
420447
return HandleCachedRealPath(*RealPath);
421448

422449
// If we have the result in the shared cache, cache it locally.
423-
auto &Shard = SharedCache.getShardForFilename(*FilenameForLookup);
450+
auto &Shard =
451+
Service.getSharedCache().getShardForFilename(*FilenameForLookup);
424452
if (const auto *ShardRealPath =
425453
Shard.findRealPathByFilename(*FilenameForLookup)) {
426454
const auto &RealPath = LocalCache.insertRealPathForFilename(

clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ using namespace dependencies;
1515
DependencyScanningService::DependencyScanningService(
1616
ScanningMode Mode, ScanningOutputFormat Format,
1717
ScanningOptimizations OptimizeArgs, bool EagerLoadModules, bool TraceVFS,
18-
std::time_t BuildSessionTimestamp)
18+
std::time_t BuildSessionTimestamp, bool CacheNegativeStats)
1919
: Mode(Mode), Format(Format), OptimizeArgs(OptimizeArgs),
2020
EagerLoadModules(EagerLoadModules), TraceVFS(TraceVFS),
21+
CacheNegativeStats(CacheNegativeStats),
2122
BuildSessionTimestamp(BuildSessionTimestamp) {}

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ DependencyScanningWorker::DependencyScanningWorker(
611611

612612
switch (Service.getMode()) {
613613
case ScanningMode::DependencyDirectivesScan:
614-
DepFS =
615-
new DependencyScanningWorkerFilesystem(Service.getSharedCache(), FS);
614+
DepFS = new DependencyScanningWorkerFilesystem(Service, FS);
616615
BaseFS = DepFS;
617616
break;
618617
case ScanningMode::CanonicalPreprocessing:

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static ScanningOutputFormat Format = ScanningOutputFormat::Make;
8585
static ScanningOptimizations OptimizeArgs;
8686
static std::string ModuleFilesDir;
8787
static bool EagerLoadModules;
88+
static bool CacheNegativeStats = true;
8889
static unsigned NumThreads = 0;
8990
static std::string CompilationDB;
9091
static std::optional<std::string> ModuleName;
@@ -191,6 +192,8 @@ static void ParseArgs(int argc, char **argv) {
191192

192193
EagerLoadModules = Args.hasArg(OPT_eager_load_pcm);
193194

195+
CacheNegativeStats = !Args.hasArg(OPT_no_cache_negative_stats);
196+
194197
if (const llvm::opt::Arg *A = Args.getLastArg(OPT_j)) {
195198
StringRef S{A->getValue()};
196199
if (!llvm::to_integer(S, NumThreads, 0)) {
@@ -1080,8 +1083,9 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
10801083
});
10811084
};
10821085

1083-
DependencyScanningService Service(ScanMode, Format, OptimizeArgs,
1084-
EagerLoadModules, /*TraceVFS=*/Verbose);
1086+
DependencyScanningService Service(
1087+
ScanMode, Format, OptimizeArgs, EagerLoadModules, /*TraceVFS=*/Verbose,
1088+
llvm::sys::toTimeT(std::chrono::system_clock::now()), CacheNegativeStats);
10851089

10861090
llvm::Timer T;
10871091
T.startTimer();

0 commit comments

Comments
 (0)