|
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,13 @@ 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 | + Filename = Filename.substr(0, Filename.find_last_of('.')); |
| 549 | + } |
| 550 | + auto SetIter = Workloads.find(Filename); |
| 551 | + |
539 | 552 | if (SetIter == Workloads.end()) { |
540 | 553 | LLVM_DEBUG(dbgs() << "[Workload] " << ModName |
541 | 554 | << " does not contain the root of any context.\n"); |
@@ -748,10 +761,18 @@ class WorkloadImportsManager : public ModuleImportsManager { |
748 | 761 | << RootVI.getSummaryList().size() << ". Skipping.\n"); |
749 | 762 | continue; |
750 | 763 | } |
751 | | - StringRef RootDefiningModule = |
752 | | - RootVI.getSummaryList().front()->modulePath(); |
753 | | - LLVM_DEBUG(dbgs() << "[Workload] Root defining module for " << RootGuid |
754 | | - << " is : " << RootDefiningModule << "\n"); |
| 764 | + std::string RootDefiningModule = |
| 765 | + RootVI.getSummaryList().front()->modulePath().str(); |
| 766 | + if (CtxprofMoveRootsToOwnModule) { |
| 767 | + RootDefiningModule = std::to_string(RootGuid); |
| 768 | + LLVM_DEBUG( |
| 769 | + dbgs() << "[Workload] Moving " << RootGuid |
| 770 | + << " to a module with the filename without extension : " |
| 771 | + << RootDefiningModule << "\n"); |
| 772 | + } else { |
| 773 | + LLVM_DEBUG(dbgs() << "[Workload] Root defining module for " << RootGuid |
| 774 | + << " is : " << RootDefiningModule << "\n"); |
| 775 | + } |
755 | 776 | auto &Set = Workloads[RootDefiningModule]; |
756 | 777 | Root.getContainedGuids(ContainedGUIDs); |
757 | 778 | for (auto Guid : ContainedGUIDs) |
|
0 commit comments