mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-23 12:24:34 +00:00
[ThinLTO] Restructure AliasSummary to contain ValueInfo of Aliasee
Summary: The AliasSummary previously contained the AliaseeGUID, which was only populated when reading the summary from bitcode. This patch changes it to instead hold the ValueInfo of the aliasee, and always populates it. This enables more efficient access to the ValueInfo (specifically in the recent patch r352438 which needed to perform an index hash table lookup using the aliasee GUID). As noted in the comments in AliasSummary, we no longer technically need to keep a pointer to the corresponding aliasee summary, since it could be obtained by walking the list of summaries on the ValueInfo looking for the summary in the same module. However, I am concerned that this would be inefficient when walking through the index during the thin link for various analyses. That can be reevaluated in the future. By always populating this new field, we can remove the guard and special handling for a 0 aliasee GUID when dumping the dot graph of the summary. An additional improvement in this patch is when reading the summaries from LLVM assembly we now set the AliaseeSummary field to the aliasee summary in that same module, which makes it consistent with the behavior when reading the summary from bitcode. Reviewers: pcc, mehdi_amini Subscribers: inglorion, eraman, steven_wu, dexonsmith, arphaman, llvm-commits Differential Revision: https://reviews.llvm.org/D57470 llvm-svn: 356268
This commit is contained in:
parent
44c4f80ee4
commit
2274d19c8e
@ -380,25 +380,35 @@ public:
|
||||
|
||||
/// Alias summary information.
|
||||
class AliasSummary : public GlobalValueSummary {
|
||||
ValueInfo AliaseeValueInfo;
|
||||
|
||||
/// This is the Aliasee in the same module as alias (could get from VI, trades
|
||||
/// memory for time). Note that this pointer may be null (and the value info
|
||||
/// empty) when we have a distributed index where the alias is being imported
|
||||
/// (as a copy of the aliasee), but the aliasee is not.
|
||||
GlobalValueSummary *AliaseeSummary;
|
||||
// AliaseeGUID is only set and accessed when we are building a combined index
|
||||
// via the BitcodeReader.
|
||||
GlobalValue::GUID AliaseeGUID;
|
||||
|
||||
public:
|
||||
AliasSummary(GVFlags Flags)
|
||||
: GlobalValueSummary(AliasKind, Flags, ArrayRef<ValueInfo>{}),
|
||||
AliaseeSummary(nullptr), AliaseeGUID(0) {}
|
||||
AliaseeSummary(nullptr) {}
|
||||
|
||||
/// Check if this is an alias summary.
|
||||
static bool classof(const GlobalValueSummary *GVS) {
|
||||
return GVS->getSummaryKind() == AliasKind;
|
||||
}
|
||||
|
||||
void setAliasee(GlobalValueSummary *Aliasee) { AliaseeSummary = Aliasee; }
|
||||
void setAliaseeGUID(GlobalValue::GUID GUID) { AliaseeGUID = GUID; }
|
||||
void setAliasee(ValueInfo &AliaseeVI, GlobalValueSummary *Aliasee) {
|
||||
AliaseeValueInfo = AliaseeVI;
|
||||
AliaseeSummary = Aliasee;
|
||||
}
|
||||
|
||||
bool hasAliasee() const { return !!AliaseeSummary; }
|
||||
bool hasAliasee() const {
|
||||
assert(!!AliaseeSummary == (AliaseeValueInfo &&
|
||||
!AliaseeValueInfo.getSummaryList().empty()) &&
|
||||
"Expect to have both aliasee summary and summary list or neither");
|
||||
return !!AliaseeSummary;
|
||||
}
|
||||
|
||||
const GlobalValueSummary &getAliasee() const {
|
||||
assert(AliaseeSummary && "Unexpected missing aliasee summary");
|
||||
@ -409,10 +419,13 @@ public:
|
||||
return const_cast<GlobalValueSummary &>(
|
||||
static_cast<const AliasSummary *>(this)->getAliasee());
|
||||
}
|
||||
bool hasAliaseeGUID() const { return AliaseeGUID != 0; }
|
||||
const GlobalValue::GUID &getAliaseeGUID() const {
|
||||
assert(AliaseeGUID && "Unexpected missing aliasee GUID");
|
||||
return AliaseeGUID;
|
||||
ValueInfo getAliaseeVI() const {
|
||||
assert(AliaseeValueInfo && "Unexpected missing aliasee");
|
||||
return AliaseeValueInfo;
|
||||
}
|
||||
GlobalValue::GUID getAliaseeGUID() const {
|
||||
assert(AliaseeValueInfo && "Unexpected missing aliasee");
|
||||
return AliaseeValueInfo.getGUID();
|
||||
}
|
||||
};
|
||||
|
||||
@ -1043,22 +1056,28 @@ public:
|
||||
OidGuidMap[OrigGUID] = ValueGUID;
|
||||
}
|
||||
|
||||
/// Find the summary for ValueInfo \p VI in module \p ModuleId, or nullptr if
|
||||
/// not found.
|
||||
GlobalValueSummary *findSummaryInModule(ValueInfo VI, StringRef ModuleId) const {
|
||||
auto SummaryList = VI.getSummaryList();
|
||||
auto Summary =
|
||||
llvm::find_if(SummaryList,
|
||||
[&](const std::unique_ptr<GlobalValueSummary> &Summary) {
|
||||
return Summary->modulePath() == ModuleId;
|
||||
});
|
||||
if (Summary == SummaryList.end())
|
||||
return nullptr;
|
||||
return Summary->get();
|
||||
}
|
||||
|
||||
/// Find the summary for global \p GUID in module \p ModuleId, or nullptr if
|
||||
/// not found.
|
||||
GlobalValueSummary *findSummaryInModule(GlobalValue::GUID ValueGUID,
|
||||
StringRef ModuleId) const {
|
||||
auto CalleeInfo = getValueInfo(ValueGUID);
|
||||
if (!CalleeInfo) {
|
||||
if (!CalleeInfo)
|
||||
return nullptr; // This function does not have a summary
|
||||
}
|
||||
auto Summary =
|
||||
llvm::find_if(CalleeInfo.getSummaryList(),
|
||||
[&](const std::unique_ptr<GlobalValueSummary> &Summary) {
|
||||
return Summary->modulePath() == ModuleId;
|
||||
});
|
||||
if (Summary == CalleeInfo.getSummaryList().end())
|
||||
return nullptr;
|
||||
return Summary->get();
|
||||
return findSummaryInModule(CalleeInfo, ModuleId);
|
||||
}
|
||||
|
||||
/// Returns the first GlobalValueSummary for \p GV, asserting that there
|
||||
|
@ -441,9 +441,11 @@ computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
|
||||
/* Live = */ false, A.isDSOLocal());
|
||||
auto AS = llvm::make_unique<AliasSummary>(Flags);
|
||||
auto *Aliasee = A.getBaseObject();
|
||||
auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
|
||||
assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
|
||||
AS->setAliasee(AliaseeSummary);
|
||||
auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
|
||||
assert(AliaseeVI && "Alias expects aliasee summary to be available");
|
||||
assert(AliaseeVI.getSummaryList().size() == 1 &&
|
||||
"Expected a single entry per aliasee in per-module index");
|
||||
AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
|
||||
if (NonRenamableLocal)
|
||||
CantBePromoted.insert(A.getGUID());
|
||||
Index.addGlobalValueSummary(A, std::move(AS));
|
||||
|
@ -7707,10 +7707,6 @@ void LLParser::AddGlobalValueToIndex(
|
||||
}
|
||||
}
|
||||
|
||||
// Add the summary if one was provided.
|
||||
if (Summary)
|
||||
Index->addGlobalValueSummary(VI, std::move(Summary));
|
||||
|
||||
// Resolve forward references from calls/refs
|
||||
auto FwdRefVIs = ForwardRefValueInfos.find(ID);
|
||||
if (FwdRefVIs != ForwardRefValueInfos.end()) {
|
||||
@ -7728,11 +7724,16 @@ void LLParser::AddGlobalValueToIndex(
|
||||
for (auto AliaseeRef : FwdRefAliasees->second) {
|
||||
assert(!AliaseeRef.first->hasAliasee() &&
|
||||
"Forward referencing alias already has aliasee");
|
||||
AliaseeRef.first->setAliasee(VI.getSummaryList().front().get());
|
||||
assert(Summary && "Aliasee must be a definition");
|
||||
AliaseeRef.first->setAliasee(VI, Summary.get());
|
||||
}
|
||||
ForwardRefAliasees.erase(FwdRefAliasees);
|
||||
}
|
||||
|
||||
// Add the summary if one was provided.
|
||||
if (Summary)
|
||||
Index->addGlobalValueSummary(VI, std::move(Summary));
|
||||
|
||||
// Save the associated ValueInfo for use in later references by ID.
|
||||
if (ID == NumberedValueInfos.size())
|
||||
NumberedValueInfos.push_back(VI);
|
||||
@ -7976,8 +7977,11 @@ bool LLParser::ParseAliasSummary(std::string Name, GlobalValue::GUID GUID,
|
||||
auto FwdRef = ForwardRefAliasees.insert(
|
||||
std::make_pair(GVId, std::vector<std::pair<AliasSummary *, LocTy>>()));
|
||||
FwdRef.first->second.push_back(std::make_pair(AS.get(), Loc));
|
||||
} else
|
||||
AS->setAliasee(AliaseeVI.getSummaryList().front().get());
|
||||
} else {
|
||||
auto Summary = Index->findSummaryInModule(AliaseeVI, ModulePath);
|
||||
assert(Summary && "Aliasee must be a definition");
|
||||
AS->setAliasee(AliaseeVI, Summary);
|
||||
}
|
||||
|
||||
AddGlobalValueToIndex(Name, GUID, (GlobalValue::LinkageTypes)GVFlags.Linkage,
|
||||
ID, std::move(AS));
|
||||
|
@ -5482,14 +5482,11 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
|
||||
// ownership.
|
||||
AS->setModulePath(getThisModule()->first());
|
||||
|
||||
GlobalValue::GUID AliaseeGUID =
|
||||
getValueInfoFromValueId(AliaseeID).first.getGUID();
|
||||
auto AliaseeInModule =
|
||||
TheIndex.findSummaryInModule(AliaseeGUID, ModulePath);
|
||||
auto AliaseeVI = getValueInfoFromValueId(AliaseeID).first;
|
||||
auto AliaseeInModule = TheIndex.findSummaryInModule(AliaseeVI, ModulePath);
|
||||
if (!AliaseeInModule)
|
||||
return error("Alias expects aliasee summary to be parsed");
|
||||
AS->setAliasee(AliaseeInModule);
|
||||
AS->setAliaseeGUID(AliaseeGUID);
|
||||
AS->setAliasee(AliaseeVI, AliaseeInModule);
|
||||
|
||||
auto GUID = getValueInfoFromValueId(ValueID);
|
||||
AS->setOriginalName(GUID.second);
|
||||
@ -5592,12 +5589,9 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
|
||||
LastSeenSummary = AS.get();
|
||||
AS->setModulePath(ModuleIdMap[ModuleId]);
|
||||
|
||||
auto AliaseeGUID =
|
||||
getValueInfoFromValueId(AliaseeValueId).first.getGUID();
|
||||
auto AliaseeInModule =
|
||||
TheIndex.findSummaryInModule(AliaseeGUID, AS->modulePath());
|
||||
AS->setAliasee(AliaseeInModule);
|
||||
AS->setAliaseeGUID(AliaseeGUID);
|
||||
auto AliaseeVI = getValueInfoFromValueId(AliaseeValueId).first;
|
||||
auto AliaseeInModule = TheIndex.findSummaryInModule(AliaseeVI, AS->modulePath());
|
||||
AS->setAliasee(AliaseeVI, AliaseeInModule);
|
||||
|
||||
ValueInfo VI = getValueInfoFromValueId(ValueID).first;
|
||||
LastSeenGUID = VI.getGUID();
|
||||
|
@ -418,17 +418,7 @@ void ModuleSummaryIndex::exportToDot(raw_ostream &OS) const {
|
||||
Draw(SummaryIt.first, R.getGUID(), R.isReadOnly() ? -1 : -2);
|
||||
|
||||
if (auto *AS = dyn_cast_or_null<AliasSummary>(SummaryIt.second)) {
|
||||
GlobalValue::GUID AliaseeId;
|
||||
if (AS->hasAliaseeGUID())
|
||||
AliaseeId = AS->getAliaseeGUID();
|
||||
else {
|
||||
auto AliaseeOrigId = AS->getAliasee().getOriginalName();
|
||||
AliaseeId = getGUIDFromOriginalID(AliaseeOrigId);
|
||||
if (!AliaseeId)
|
||||
AliaseeId = AliaseeOrigId;
|
||||
}
|
||||
|
||||
Draw(SummaryIt.first, AliaseeId, -3);
|
||||
Draw(SummaryIt.first, AS->getAliaseeGUID(), -3);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -821,12 +821,7 @@ void llvm::computeDeadSymbols(
|
||||
// If this is an alias, visit the aliasee VI to ensure that all copies
|
||||
// are marked live and it is added to the worklist for further
|
||||
// processing of its references.
|
||||
// FIXME: The aliasee GUID is only populated in the summary when we
|
||||
// read them from bitcode, which is currently the only way we can
|
||||
// get here (we don't yet support reading the summary index directly
|
||||
// from LLVM assembly code in tools that can perform a thin link).
|
||||
// If that ever changes, the below call to getAliaseGUID will assert.
|
||||
visit(Index.getValueInfo(AS->getAliaseeGUID()));
|
||||
visit(AS->getAliaseeVI());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,9 @@
|
||||
; PERMODULE-NEXT: M0_[[MAIN_ALIAS:[0-9]+]] [style="dotted,filled",shape="box",label="main_alias",fillcolor="red"]; // alias, dead
|
||||
; PERMODULE-NEXT: M0_[[MAIN:[0-9]+]] [shape="record",label="main|extern (inst: 4, ffl: 00000)}",fillcolor="red"]; // function, dead
|
||||
; PERMODULE-NEXT: // Edges:
|
||||
; PERMODULE-NEXT: M0_[[MAIN_ALIAS]] -> M0_[[MAIN]] [style=dotted]; // alias
|
||||
; PERMODULE-NEXT: }
|
||||
; PERMODULE-NEXT: // Cross-module edges:
|
||||
; PERMODULE-NEXT: 0 [label="@0"]; // defined externally
|
||||
; PERMODULE-NEXT: M0_[[MAIN_ALIAS]] -> 0 [style=dotted]; // alias
|
||||
; PERMODULE-NEXT: [[A:[0-9]+]] [label="A"]; // defined externally
|
||||
; PERMODULE-NEXT: M0_[[MAIN]] -> [[A]] [style=dashed,color=forestgreen]; // const-ref
|
||||
; PERMODULE-NEXT: [[FOO:[0-9]+]] [label="foo"]; // defined externally
|
||||
|
Loading…
x
Reference in New Issue
Block a user