Skip to content

Commit dbd7ce0

Browse files
[IR] Inroduce ModuleToSummariesForIndexTy (NFC) (#105906)
This patch introduces type alias ModuleToSummariesForIndexTy. I'm planning to change the type slightly to allow heterogeneous lookup (that is, std::map<K, V, std::less<>>) in a subsequent patch. The problem is that changing the type affects many places. Using a type alias reduces the impact.
1 parent ca53611 commit dbd7ce0

File tree

9 files changed

+30
-27
lines changed

9 files changed

+30
-27
lines changed

llvm/include/llvm/Bitcode/BitcodeWriter.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ class BitcodeWriter {
100100
void writeThinLinkBitcode(const Module &M, const ModuleSummaryIndex &Index,
101101
const ModuleHash &ModHash);
102102

103-
void writeIndex(
104-
const ModuleSummaryIndex *Index,
105-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
106-
const GVSummaryPtrSet *DecSummaries);
103+
void writeIndex(const ModuleSummaryIndex *Index,
104+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex,
105+
const GVSummaryPtrSet *DecSummaries);
107106
};
108107

109108
/// Write the specified module to the specified raw output stream.
@@ -150,10 +149,10 @@ void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
150149
/// index for a distributed backend, provide the \p ModuleToSummariesForIndex
151150
/// map. \p DecSummaries specifies the set of summaries for which the
152151
/// corresponding value should be imported as a declaration (prototype).
153-
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
154-
const std::map<std::string, GVSummaryMapTy>
155-
*ModuleToSummariesForIndex = nullptr,
156-
const GVSummaryPtrSet *DecSummaries = nullptr);
152+
void writeIndexToFile(
153+
const ModuleSummaryIndex &Index, raw_ostream &Out,
154+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex = nullptr,
155+
const GVSummaryPtrSet *DecSummaries = nullptr);
157156

158157
/// If EmbedBitcode is set, save a copy of the llvm IR as data in the
159158
/// __LLVM,__bitcode section (.llvmbc on non-MacOS).

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,10 @@ using ModulePathStringTableTy = StringMap<ModuleHash>;
12911291
/// a particular module, and provide efficient access to their summary.
12921292
using GVSummaryMapTy = DenseMap<GlobalValue::GUID, GlobalValueSummary *>;
12931293

1294+
/// Map of a module name to the GUIDs and summaries we will import from that
1295+
/// module.
1296+
using ModuleToSummariesForIndexTy = std::map<std::string, GVSummaryMapTy>;
1297+
12941298
/// A set of global value summary pointers.
12951299
using GVSummaryPtrSet = std::unordered_set<GlobalValueSummary *>;
12961300

llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class ThinLTOCodeGenerator {
276276
*/
277277
void gatherImportedSummariesForModule(
278278
Module &Module, ModuleSummaryIndex &Index,
279-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
279+
ModuleToSummariesForIndexTy &ModuleToSummariesForIndex,
280280
GVSummaryPtrSet &DecSummaries, const lto::InputFile &File);
281281

282282
/**

llvm/include/llvm/Transforms/IPO/FunctionImport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ void gatherImportedSummariesForModule(
262262
StringRef ModulePath,
263263
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
264264
const FunctionImporter::ImportMapTy &ImportList,
265-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
265+
ModuleToSummariesForIndexTy &ModuleToSummariesForIndex,
266266
GVSummaryPtrSet &DecSummaries);
267267

268268
/// Emit into \p OutputFilename the files module \p ModulePath will import from.
269-
std::error_code EmitImportsFiles(
270-
StringRef ModulePath, StringRef OutputFilename,
271-
const std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
269+
std::error_code
270+
EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename,
271+
const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex);
272272

273273
/// Based on the information recorded in the summaries during global
274274
/// summary-based analysis:

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
432432

433433
/// When writing a subset of the index for distributed backends, client
434434
/// provides a map of modules to the corresponding GUIDs/summaries to write.
435-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
435+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex;
436436

437437
/// Map that holds the correspondence between the GUID used in the combined
438438
/// index and a value id generated by this class to use in references.
@@ -461,11 +461,11 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
461461
/// If provided, \p DecSummaries specifies the set of summaries for which
462462
/// the corresponding functions or aliased functions should be imported as a
463463
/// declaration (but not definition) for each module.
464-
IndexBitcodeWriter(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
465-
const ModuleSummaryIndex &Index,
466-
const GVSummaryPtrSet *DecSummaries = nullptr,
467-
const std::map<std::string, GVSummaryMapTy>
468-
*ModuleToSummariesForIndex = nullptr)
464+
IndexBitcodeWriter(
465+
BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
466+
const ModuleSummaryIndex &Index,
467+
const GVSummaryPtrSet *DecSummaries = nullptr,
468+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex = nullptr)
469469
: BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
470470
DecSummaries(DecSummaries),
471471
ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
@@ -5102,7 +5102,7 @@ void BitcodeWriter::writeModule(const Module &M,
51025102

51035103
void BitcodeWriter::writeIndex(
51045104
const ModuleSummaryIndex *Index,
5105-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5105+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex,
51065106
const GVSummaryPtrSet *DecSummaries) {
51075107
IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
51085108
ModuleToSummariesForIndex);
@@ -5159,7 +5159,7 @@ void IndexBitcodeWriter::write() {
51595159
// index for a distributed backend, provide a \p ModuleToSummariesForIndex map.
51605160
void llvm::writeIndexToFile(
51615161
const ModuleSummaryIndex &Index, raw_ostream &Out,
5162-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5162+
const ModuleToSummariesForIndexTy *ModuleToSummariesForIndex,
51635163
const GVSummaryPtrSet *DecSummaries) {
51645164
SmallVector<char, 0> Buffer;
51655165
Buffer.reserve(256 * 1024);

llvm/lib/LTO/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ class lto::ThinBackendProc {
13991399
Error emitFiles(const FunctionImporter::ImportMapTy &ImportList,
14001400
llvm::StringRef ModulePath,
14011401
const std::string &NewModulePath) {
1402-
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
1402+
ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
14031403
GVSummaryPtrSet DeclarationSummaries;
14041404

14051405
std::error_code EC;

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
762762
*/
763763
void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
764764
Module &TheModule, ModuleSummaryIndex &Index,
765-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
765+
ModuleToSummariesForIndexTy &ModuleToSummariesForIndex,
766766
GVSummaryPtrSet &DecSummaries, const lto::InputFile &File) {
767767
auto ModuleCount = Index.modulePaths().size();
768768
auto ModuleIdentifier = TheModule.getModuleIdentifier();
@@ -833,7 +833,7 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
833833
// the set of keys in `ModuleToSummariesForIndex` should be a superset of keys
834834
// in `DecSummaries`, so no need to use `DecSummaries` in `EmitImportFiles`.
835835
GVSummaryPtrSet DecSummaries;
836-
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
836+
ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
837837
llvm::gatherImportedSummariesForModule(
838838
ModuleIdentifier, ModuleToDefinedGVSummaries,
839839
ImportLists[ModuleIdentifier], ModuleToSummariesForIndex, DecSummaries);

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ void llvm::gatherImportedSummariesForModule(
14851485
StringRef ModulePath,
14861486
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
14871487
const FunctionImporter::ImportMapTy &ImportList,
1488-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
1488+
ModuleToSummariesForIndexTy &ModuleToSummariesForIndex,
14891489
GVSummaryPtrSet &DecSummaries) {
14901490
// Include all summaries from the importing module.
14911491
ModuleToSummariesForIndex[std::string(ModulePath)] =
@@ -1511,7 +1511,7 @@ void llvm::gatherImportedSummariesForModule(
15111511
/// Emit the files \p ModulePath will import from into \p OutputFilename.
15121512
std::error_code llvm::EmitImportsFiles(
15131513
StringRef ModulePath, StringRef OutputFilename,
1514-
const std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
1514+
const ModuleToSummariesForIndexTy &ModuleToSummariesForIndex) {
15151515
std::error_code EC;
15161516
raw_fd_ostream ImportsOS(OutputFilename, EC, sys::fs::OpenFlags::OF_Text);
15171517
if (EC)

llvm/tools/llvm-lto/llvm-lto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ class ThinLTOProcessing {
691691

692692
// Build a map of module to the GUIDs and summary objects that should
693693
// be written to its index.
694-
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
694+
ModuleToSummariesForIndexTy ModuleToSummariesForIndex;
695695
GVSummaryPtrSet DecSummaries;
696696
ThinGenerator.gatherImportedSummariesForModule(
697697
*TheModule, *Index, ModuleToSummariesForIndex, DecSummaries, *Input);

0 commit comments

Comments
 (0)