Skip to content

Commit d6cd214

Browse files
[ThinLTO][LowerTypeTests] Don't compute address taken set unless CFI (NFC) (#118508)
The AddressTaken set used for CFI with regular LTO was being computed on the ExportSummary regardless of whether any CFI metadata existed. In the case of ThinLTO, the ExportSummary is the global summary index for the target, and the lack of guard in this code meant this was being computed on the ThinLTO index even when there was an empty regular LTO module, since the backend is called on the combined module to generate the expected output file (normally this is trivial as there is no IR). Move the computation of the AddressTaken set into the condition checking for CFI to avoid this overhead. This change resulted in a 20% speedup in the thin link of a large target. It looks like the outer loop has existed here for several years, but likely became a larger overhead after the inner loop was added very recently in PR113987. I will send a separate patch to refactor the ThinLTO backend handling to avoid invoking the opt pipeline if the module is empty, in case there are other summary-based analyses in some of the passes now or in the future. This change is still desireable as by default regular LTO modules contain summaries, or we can have split thin and regular LTO modules, and if they don't involve CFI these would still unnecessarily compute the AddressTaken set.
1 parent 2d57333 commit d6cd214

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,20 +2090,19 @@ bool LowerTypeTestsModule::lower() {
20902090
};
20912091
MapVector<StringRef, ExportedFunctionInfo> ExportedFunctions;
20922092
if (ExportSummary) {
2093-
// A set of all functions that are address taken by a live global object.
2094-
DenseSet<GlobalValue::GUID> AddressTaken;
2095-
for (auto &I : *ExportSummary)
2096-
for (auto &GVS : I.second.SummaryList)
2097-
if (GVS->isLive())
2098-
for (const auto &Ref : GVS->refs()) {
2099-
AddressTaken.insert(Ref.getGUID());
2100-
for (auto &RefGVS : Ref.getSummaryList())
2101-
if (auto Alias = dyn_cast<AliasSummary>(RefGVS.get()))
2102-
AddressTaken.insert(Alias->getAliaseeGUID());
2103-
}
2104-
21052093
NamedMDNode *CfiFunctionsMD = M.getNamedMetadata("cfi.functions");
21062094
if (CfiFunctionsMD) {
2095+
// A set of all functions that are address taken by a live global object.
2096+
DenseSet<GlobalValue::GUID> AddressTaken;
2097+
for (auto &I : *ExportSummary)
2098+
for (auto &GVS : I.second.SummaryList)
2099+
if (GVS->isLive())
2100+
for (const auto &Ref : GVS->refs()) {
2101+
AddressTaken.insert(Ref.getGUID());
2102+
for (auto &RefGVS : Ref.getSummaryList())
2103+
if (auto Alias = dyn_cast<AliasSummary>(RefGVS.get()))
2104+
AddressTaken.insert(Alias->getAliaseeGUID());
2105+
}
21072106
for (auto *FuncMD : CfiFunctionsMD->operands()) {
21082107
assert(FuncMD->getNumOperands() >= 2);
21092108
StringRef FunctionName =

0 commit comments

Comments
 (0)