|
38 | 38 | #include "llvm/Support/ErrorHandling.h"
|
39 | 39 | #include "llvm/Support/FileSystem.h"
|
40 | 40 | #include "llvm/Support/JSON.h"
|
| 41 | +#include "llvm/Support/Path.h" |
41 | 42 | #include "llvm/Support/SourceMgr.h"
|
42 | 43 | #include "llvm/Support/raw_ostream.h"
|
43 | 44 | #include "llvm/Transforms/IPO/Internalize.h"
|
@@ -175,6 +176,12 @@ static cl::opt<std::string> WorkloadDefinitions(
|
175 | 176 |
|
176 | 177 | extern cl::opt<std::string> UseCtxProfile;
|
177 | 178 |
|
| 179 | +static cl::opt<bool> CtxprofMoveRootsToOwnModule( |
| 180 | + "thinlto-move-ctxprof-trees", |
| 181 | + cl::desc("Move contextual profiling roots and the graphs under them in " |
| 182 | + "their own module."), |
| 183 | + cl::Hidden, cl::init(false)); |
| 184 | + |
178 | 185 | namespace llvm {
|
179 | 186 | extern cl::opt<bool> EnableMemProfContextDisambiguation;
|
180 | 187 | }
|
@@ -535,7 +542,14 @@ class WorkloadImportsManager : public ModuleImportsManager {
|
535 | 542 | computeImportForModule(const GVSummaryMapTy &DefinedGVSummaries,
|
536 | 543 | StringRef ModName,
|
537 | 544 | FunctionImporter::ImportMapTy &ImportList) override {
|
538 |
| - auto SetIter = Workloads.find(ModName); |
| 545 | + StringRef Filename = ModName; |
| 546 | + if (CtxprofMoveRootsToOwnModule) { |
| 547 | + Filename = sys::path::filename(ModName); |
| 548 | + // Drop the file extension. |
| 549 | + Filename = Filename.substr(0, Filename.find_last_of('.')); |
| 550 | + } |
| 551 | + auto SetIter = Workloads.find(Filename); |
| 552 | + |
539 | 553 | if (SetIter == Workloads.end()) {
|
540 | 554 | LLVM_DEBUG(dbgs() << "[Workload] " << ModName
|
541 | 555 | << " does not contain the root of any context.\n");
|
@@ -748,10 +762,18 @@ class WorkloadImportsManager : public ModuleImportsManager {
|
748 | 762 | << RootVI.getSummaryList().size() << ". Skipping.\n");
|
749 | 763 | continue;
|
750 | 764 | }
|
751 |
| - StringRef RootDefiningModule = |
752 |
| - RootVI.getSummaryList().front()->modulePath(); |
753 |
| - LLVM_DEBUG(dbgs() << "[Workload] Root defining module for " << RootGuid |
754 |
| - << " is : " << RootDefiningModule << "\n"); |
| 765 | + std::string RootDefiningModule = |
| 766 | + RootVI.getSummaryList().front()->modulePath().str(); |
| 767 | + if (CtxprofMoveRootsToOwnModule) { |
| 768 | + RootDefiningModule = std::to_string(RootGuid); |
| 769 | + LLVM_DEBUG( |
| 770 | + dbgs() << "[Workload] Moving " << RootGuid |
| 771 | + << " to a module with the filename without extension : " |
| 772 | + << RootDefiningModule << "\n"); |
| 773 | + } else { |
| 774 | + LLVM_DEBUG(dbgs() << "[Workload] Root defining module for " << RootGuid |
| 775 | + << " is : " << RootDefiningModule << "\n"); |
| 776 | + } |
755 | 777 | auto &Set = Workloads[RootDefiningModule];
|
756 | 778 | Root.getContainedGuids(ContainedGUIDs);
|
757 | 779 | for (auto Guid : ContainedGUIDs)
|
|
0 commit comments