mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-04 08:04:37 +08:00
Name program modules by the entry's file name so profiles match in every checkout
Each partition's source file name was the program entry's absolute path, and profiles name a module's local functions after it. Since programs keep partition-local functions internal (#2449), a profile collected in one directory missed those functions in builds from any other: a native compiler profile collected on main named 27% of its records, holding 2.2% of its counts, after the checkout's path. Modules now carry the entry's file name. The partition cache key still includes the full path.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include "llvm/Support/Caching.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/SHA256.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/ThreadPool.h"
|
||||
@@ -381,6 +382,14 @@ std::optional<EmitFailure> inspectProfile(const EmitOptions &Options) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// The source file name a program's modules carry: the entry's file name,
|
||||
// without its directory. Profiles name a module's local functions after it
|
||||
// ("<name>;<function>"), so a profile collected in one checkout matches the
|
||||
// builds of every other one.
|
||||
std::string moduleSourceName(StringRef SourcePath) {
|
||||
return sys::path::filename(SourcePath).str();
|
||||
}
|
||||
|
||||
// Owns the analysis managers a pipeline needs for one module.
|
||||
struct Pipeline {
|
||||
PassInstrumentationCallbacks Callbacks;
|
||||
@@ -703,7 +712,7 @@ Expected<std::unique_ptr<Module>> loadPartition(const EmitOptions &Options,
|
||||
return createStringError(inconvertibleErrorCode(), Stream.str());
|
||||
}
|
||||
if (!Options.SourcePath.empty())
|
||||
Mod->setSourceFileName(Options.SourcePath);
|
||||
Mod->setSourceFileName(moduleSourceName(Options.SourcePath));
|
||||
Mod->setTargetTriple(Triple(Options.Target));
|
||||
Mod->setDataLayout(Machine.createDataLayout());
|
||||
if (std::optional<EmitFailure> Failure = verify(*Mod, "verification_failed"))
|
||||
@@ -1555,7 +1564,7 @@ int emit(const EmitOptions &Options) {
|
||||
return reportError("invalid_ir", Stream.str(), Options.DiagnosticFormat);
|
||||
}
|
||||
if (!Options.SourcePath.empty())
|
||||
Mod->setSourceFileName(Options.SourcePath);
|
||||
Mod->setSourceFileName(moduleSourceName(Options.SourcePath));
|
||||
|
||||
std::string LookupError;
|
||||
std::unique_ptr<TargetMachine> Machine =
|
||||
|
||||
Reference in New Issue
Block a user