[PATCH] D91676: Avoid redundant work when computing vtable vcall visibility
Teresa Johnson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 17 20:05:56 PST 2020
tejohnson created this revision.
tejohnson added reviewers: pcc, ostannard.
Herald added a project: clang.
tejohnson requested review of this revision.
Add a Visited set to avoid repeatedly processing the same base classes
in complex class hierarchies. This cut down the compile time of one
source file from >12min to ~1min.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91676
Files:
clang/lib/CodeGen/CGVTables.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/MicrosoftCXXABI.cpp
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1649,8 +1649,9 @@
// TODO: Should VirtualFunctionElimination also be supported here?
// See similar handling in CodeGenModule::EmitVTableTypeMetadata.
if (CGM.getCodeGenOpts().WholeProgramVTables) {
+ llvm::DenseSet<const CXXRecordDecl *> Visited;
llvm::GlobalObject::VCallVisibility TypeVis =
- CGM.GetVCallVisibilityLevel(RD);
+ CGM.GetVCallVisibilityLevel(RD, Visited);
if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
VTable->setVCallVisibilityMetadata(TypeVis);
}
Index: clang/lib/CodeGen/CodeGenModule.h
===================================================================
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1333,8 +1333,11 @@
/// a virtual function call could be made which ends up being dispatched to a
/// member function of this class. This scope can be wider than the visibility
/// of the class itself when the class has a more-visible dynamic base class.
+ /// The client should pass in an empty Visited set, which is used to prevent
+ /// redundant recursive processing.
llvm::GlobalObject::VCallVisibility
- GetVCallVisibilityLevel(const CXXRecordDecl *RD);
+ GetVCallVisibilityLevel(const CXXRecordDecl *RD,
+ llvm::DenseSet<const CXXRecordDecl *> &Visited);
/// Emit type metadata for the given vtable using the given layout.
void EmitVTableTypeMetadata(const CXXRecordDecl *RD,
Index: clang/lib/CodeGen/CGVTables.cpp
===================================================================
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -1294,8 +1294,13 @@
return !HasLTOVisibilityPublicStd(RD);
}
-llvm::GlobalObject::VCallVisibility
-CodeGenModule::GetVCallVisibilityLevel(const CXXRecordDecl *RD) {
+llvm::GlobalObject::VCallVisibility CodeGenModule::GetVCallVisibilityLevel(
+ const CXXRecordDecl *RD, llvm::DenseSet<const CXXRecordDecl *> &Visited) {
+ // If we have already visited this RD, return the max visibility, so that it
+ // has no effect on the min visibility computed below by the recursive caller.
+ if (!Visited.insert(RD).second)
+ return llvm::GlobalObject::VCallVisibilityTranslationUnit;
+
LinkageInfo LV = RD->getLinkageAndVisibility();
llvm::GlobalObject::VCallVisibility TypeVis;
if (!isExternallyVisible(LV.getLinkage()))
@@ -1307,13 +1312,15 @@
for (auto B : RD->bases())
if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
- TypeVis = std::min(TypeVis,
- GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl()));
+ TypeVis = std::min(
+ TypeVis,
+ GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl(), Visited));
for (auto B : RD->vbases())
if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
- TypeVis = std::min(TypeVis,
- GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl()));
+ TypeVis = std::min(
+ TypeVis,
+ GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl(), Visited));
return TypeVis;
}
@@ -1382,7 +1389,9 @@
if (getCodeGenOpts().VirtualFunctionElimination ||
getCodeGenOpts().WholeProgramVTables) {
- llvm::GlobalObject::VCallVisibility TypeVis = GetVCallVisibilityLevel(RD);
+ llvm::DenseSet<const CXXRecordDecl *> Visited;
+ llvm::GlobalObject::VCallVisibility TypeVis =
+ GetVCallVisibilityLevel(RD, Visited);
if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
VTable->setVCallVisibilityMetadata(TypeVis);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91676.305961.patch
Type: text/x-patch
Size: 3765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201118/ae3e3ba4/attachment.bin>
More information about the cfe-commits
mailing list