Skip to content

Commit

Permalink
[Clang] Emit type metadata on vtables when IRPGO instrumentation opti…
Browse files Browse the repository at this point in the history
…on 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
  • Loading branch information
minglotus-6 committed Nov 3, 2023
1 parent c7a7a43 commit 34c0d32
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 102 deletions.
5 changes: 4 additions & 1 deletion clang/lib/CodeGen/CGVTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,10 @@ llvm::GlobalObject::VCallVisibility CodeGenModule::GetVCallVisibilityLevel(
void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable,
const VTableLayout &VTLayout) {
if (!getCodeGenOpts().LTOUnit)
// Emit type metadata on vtables with LTO or IR instrumentation.
// In IR instrumentation, the type metadata is used to find out vtable
// definitions (for type profiling) among all global variables.
if (!getCodeGenOpts().LTOUnit && !getCodeGenOpts().hasProfileIRInstr())
return;

CharUnits ComponentWidth = GetTargetTypeStoreSize(getVTableComponentType());
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/CodeGen/MicrosoftCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,11 @@ void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
void MicrosoftCXXABI::emitVTableTypeMetadata(const VPtrInfo &Info,
const CXXRecordDecl *RD,
llvm::GlobalVariable *VTable) {
if (!CGM.getCodeGenOpts().LTOUnit)
// Emit type metadata on vtables with LTO or IR instrumentation.
// In IR instrumentation, the type metadata could be used to find out vtable
// definitions (for type profiling) among all global variables.
if (!CGM.getCodeGenOpts().LTOUnit &&
!CGM.getCodeGenOpts().hasProfileIRInstr())
return;

// TODO: Should VirtualFunctionElimination also be supported here?
Expand Down

0 comments on commit 34c0d32

Please sign in to comment.