Skip to content

Commit 34c0d32

Browse files
[Clang] Emit type metadata on vtables when IRPGO instrumentation option is on. (#70841)
The motivating use case is to have type metadata on vtables if IR instrumentation is on (without the requirement of`-fwhole-program-vtables` or `-flto`). A related rfc is in https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600
1 parent c7a7a43 commit 34c0d32

File tree

3 files changed

+129
-102
lines changed

3 files changed

+129
-102
lines changed

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,10 @@ llvm::GlobalObject::VCallVisibility CodeGenModule::GetVCallVisibilityLevel(
13121312
void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
13131313
llvm::GlobalVariable *VTable,
13141314
const VTableLayout &VTLayout) {
1315-
if (!getCodeGenOpts().LTOUnit)
1315+
// Emit type metadata on vtables with LTO or IR instrumentation.
1316+
// In IR instrumentation, the type metadata is used to find out vtable
1317+
// definitions (for type profiling) among all global variables.
1318+
if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr())
13161319
return;
13171320

13181321
CharUnits ComponentWidth = GetTargetTypeStoreSize(getVTableComponentType());

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,11 @@ void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
16731673
void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info,
16741674
const CXXRecordDecl *RD,
16751675
llvm::GlobalVariable *VTable) {
1676-
if (!CGM.getCodeGenOpts().LTOUnit)
1676+
// Emit type metadata on vtables with LTO or IR instrumentation.
1677+
// In IR instrumentation, the type metadata could be used to find out vtable
1678+
// definitions (for type profiling) among all global variables.
1679+
if (!CGM.getCodeGenOpts().LTOUnit &&
1680+
!CGM.getCodeGenOpts().hasProfileIRInstr())
16771681
return;
16781682

16791683
// TODO: Should VirtualFunctionElimination also be supported here?

0 commit comments

Comments
 (0)