diff options
| author | mingmingl <mingmingl@google.com> | 2025-11-11 09:36:50 -0800 |
|---|---|---|
| committer | mingmingl <mingmingl@google.com> | 2025-11-11 09:36:50 -0800 |
| commit | 51d8b13194fe401d9e1f4ea09ba226483a0a5a3d (patch) | |
| tree | 4ee1c2c501fc6397169790675be8d40ee4a212f8 /clang/lib/CodeGen/CGClass.cpp | |
| parent | eb1297910e361628719c1c5d81e60ca4e32fb64f (diff) | |
Introduce intrinsic for vtable profilingusers/mingmingl-llvm/intrinsic
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 8346ee3aa6a8..71b6873ec0db 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -2769,12 +2769,15 @@ LeastDerivedClassWithSameLayout(const CXXRecordDecl *RD) { void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, llvm::Value *VTable, SourceLocation Loc) { + const bool EmitTypeTests = (CGM.getCodeGenOpts().WholeProgramVTables && + // Don't insert type test assumes if we are + // forcing public visibility. + !CGM.AlwaysHasLTOVisibilityPublic(RD)); + // TODO: Add a new Clang option. + const bool EmitInstrTypeTests = CGM.getCodeGenOpts().hasProfileIRInstr(); if (SanOpts.has(SanitizerKind::CFIVCall)) EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc); - else if (CGM.getCodeGenOpts().WholeProgramVTables && - // Don't insert type test assumes if we are forcing public - // visibility. - !CGM.AlwaysHasLTOVisibilityPublic(RD)) { + else if (EmitTypeTests || EmitInstrTypeTests) { CanQualType Ty = CGM.getContext().getCanonicalTagType(RD); llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(Ty); llvm::Value *TypeId = @@ -2784,9 +2787,14 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD, // @llvm.type.test(). Otherwise emit @llvm.public.type.test(), which WPD // will convert to @llvm.type.test() if we assert at link time that we have // whole program visibility. - llvm::Intrinsic::ID IID = CGM.HasHiddenLTOVisibility(RD) - ? llvm::Intrinsic::type_test - : llvm::Intrinsic::public_type_test; + llvm::Intrinsic::ID IID; + if (EmitTypeTests) { + IID = CGM.HasHiddenLTOVisibility(RD) ? llvm::Intrinsic::type_test + : llvm::Intrinsic::public_type_test; + } else { + assert(EmitInstrTypeTests && "expected EmitInstrTypeTests"); + IID = llvm::Intrinsic::instr_type_test; + } llvm::Value *TypeTest = Builder.CreateCall(CGM.getIntrinsic(IID), {VTable, TypeId}); Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest); |
