[ThinLTO] Enable importing of aliases as copy of aliasee

Summary:
This implements a missing feature to allow importing of aliases, which
was previously disabled because alias cannot be available_externally.
We instead import an alias as a copy of its aliasee.

Some additional work was required in the IndexBitcodeWriter for the
distributed build case, to ensure that the aliasee has a value id
in the distributed index file (i.e. even when it is not being
imported directly).

This is a performance win in codes that have many aliases, e.g. C++
applications that have many constructor and destructor aliases.

Reviewers: pcc

Subscribers: mehdi_amini, inglorion, eraman, llvm-commits

Differential Revision: https://reviews.llvm.org/D40747

llvm-svn: 320895
This commit is contained in:
Teresa Johnson
2017-12-16 00:18:12 +00:00
parent c4fdbca604
commit 81bbf74265
14 changed files with 236 additions and 81 deletions

View File

@@ -413,7 +413,7 @@ public:
// in writing out the call graph edges. Save the mapping from GUID
// to the new global value id to use when writing those edges, which
// are currently saved in the index in terms of GUID.
forEachSummary([&](GVInfo I) {
forEachSummary([&](GVInfo I, bool) {
GUIDToValueIdMap[I.first] = ++GlobalValueId;
});
}
@@ -428,12 +428,18 @@ public:
void forEachSummary(Functor Callback) {
if (ModuleToSummariesForIndex) {
for (auto &M : *ModuleToSummariesForIndex)
for (auto &Summary : M.second)
Callback(Summary);
for (auto &Summary : M.second) {
Callback(Summary, false);
// Ensure aliasee is handled, e.g. for assigning a valueId,
// even if we are not importing the aliasee directly (the
// imported alias will contain a copy of aliasee).
if (auto *AS = dyn_cast<AliasSummary>(Summary.getSecond()))
Callback({AS->getAliaseeGUID(), &AS->getAliasee()}, true);
}
} else {
for (auto &Summaries : Index)
for (auto &Summary : Summaries.second.SummaryList)
Callback({Summaries.first, Summary.get()});
Callback({Summaries.first, Summary.get()}, false);
}
}
@@ -3604,7 +3610,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.clear();
};
forEachSummary([&](GVInfo I) {
forEachSummary([&](GVInfo I, bool IsAliasee) {
GlobalValueSummary *S = I.second;
assert(S);
@@ -3612,6 +3618,12 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
assert(ValueId);
SummaryToValueIdMap[S] = *ValueId;
// If this is invoked for an aliasee, we want to record the above
// mapping, but then not emit a summary entry (if the aliasee is
// to be imported, we will invoke this separately with IsAliasee=false).
if (IsAliasee)
return;
if (auto *AS = dyn_cast<AliasSummary>(S)) {
// Will process aliases as a post-pass because the reader wants all
// global to be loaded first.