r374844 - Revert "Dead Virtual Function Elimination"

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 14 17:06:07 PDT 2019


Hi Jorge,

Please mention the reason for a revert in revert commit messages. Also,
until SVN stops being our system of record, please use SVN revision numbers
to reference prior commits in reverts.

On Mon, 14 Oct 2019 at 16:22, Jorge Gorbe Moya via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: jgorbe
> Date: Mon Oct 14 16:25:25 2019
> New Revision: 374844
>
> URL: http://llvm.org/viewvc/llvm-project?rev=374844&view=rev
> Log:
> Revert "Dead Virtual Function Elimination"
>
> This reverts commit 9f6a873268e1ad9855873d9d8007086c0d01cf4f.
>
> Removed:
>     cfe/trunk/test/CodeGenCXX/vcall-visibility-metadata.cpp
>     cfe/trunk/test/CodeGenCXX/virtual-function-elimination.cpp
>     cfe/trunk/test/Driver/virtual-function-elimination.cpp
> Modified:
>     cfe/trunk/include/clang/Basic/CodeGenOptions.def
>     cfe/trunk/include/clang/Driver/Options.td
>     cfe/trunk/lib/CodeGen/CGClass.cpp
>     cfe/trunk/lib/CodeGen/CGVTables.cpp
>     cfe/trunk/lib/CodeGen/CodeGenModule.h
>     cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
>     cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>
> Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.def?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/CodeGenOptions.def (original)
> +++ cfe/trunk/include/clang/Basic/CodeGenOptions.def Mon Oct 14 16:25:25
> 2019
> @@ -278,10 +278,6 @@ CODEGENOPT(EmitLLVMUseLists, 1, 0) ///<
>  CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program
>                                        ///  vtable optimization.
>
> -CODEGENOPT(VirtualFunctionElimination, 1, 0) ///< Whether to apply the
> dead
> -                                             /// virtual function
> elimination
> -                                             /// optimization.
> -
>  /// Whether to use public LTO visibility for entities in std and stdext
>  /// namespaces. This is enabled by clang-cl's /MT and /MTd flags.
>  CODEGENOPT(LTOVisibilityPublicStd, 1, 0)
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Mon Oct 14 16:25:25 2019
> @@ -1863,13 +1863,6 @@ def fforce_emit_vtables : Flag<["-"], "f
>      HelpText<"Emits more virtual tables to improve devirtualization">;
>  def fno_force_emit_vtables : Flag<["-"], "fno-force-emit-vtables">,
> Group<f_Group>,
>    Flags<[CoreOption]>;
> -
> -def fvirtual_function_elimination : Flag<["-"],
> "fvirtual-function-elimination">, Group<f_Group>,
> -  Flags<[CoreOption, CC1Option]>,
> -  HelpText<"Enables dead virtual function elimination optimization.
> Requires -flto=full">;
> -def fno_virtual_function_elimination : Flag<["-"],
> "fno-virtual-function_elimination">, Group<f_Group>,
> -  Flags<[CoreOption]>;
> -
>  def fwrapv : Flag<["-"], "fwrapv">, Group<f_Group>, Flags<[CC1Option]>,
>    HelpText<"Treat signed integer overflow as two's complement">;
>  def fwritable_strings : Flag<["-"], "fwritable-strings">, Group<f_Group>,
> Flags<[CC1Option]>,
>
> Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Oct 14 16:25:25 2019
> @@ -2784,16 +2784,11 @@ void CodeGenFunction::EmitVTablePtrCheck
>
>  bool CodeGenFunction::ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl
> *RD) {
>    if (!CGM.getCodeGenOpts().WholeProgramVTables ||
> +      !SanOpts.has(SanitizerKind::CFIVCall) ||
> +      !CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall) ||
>        !CGM.HasHiddenLTOVisibility(RD))
>      return false;
>
> -  if (CGM.getCodeGenOpts().VirtualFunctionElimination)
> -    return true;
> -
> -  if (!SanOpts.has(SanitizerKind::CFIVCall) ||
> -      !CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIVCall))
> -    return false;
> -
>    std::string TypeName = RD->getQualifiedNameAsString();
>    return !getContext().getSanitizerBlacklist().isBlacklistedType(
>        SanitizerKind::CFIVCall, TypeName);
> @@ -2816,13 +2811,8 @@ llvm::Value *CodeGenFunction::EmitVTable
>         TypeId});
>    llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
>
> -  std::string TypeName = RD->getQualifiedNameAsString();
> -  if (SanOpts.has(SanitizerKind::CFIVCall) &&
> -      !getContext().getSanitizerBlacklist().isBlacklistedType(
> -          SanitizerKind::CFIVCall, TypeName)) {
> -    EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall),
> -              SanitizerHandler::CFICheckFail, {}, {});
> -  }
> +  EmitCheck(std::make_pair(CheckResult, SanitizerKind::CFIVCall),
> +            SanitizerHandler::CFICheckFail, nullptr, nullptr);
>
>    return Builder.CreateBitCast(
>        Builder.CreateExtractValue(CheckedLoad, 0),
>
> Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGVTables.cpp Mon Oct 14 16:25:25 2019
> @@ -808,7 +808,7 @@ CodeGenVTables::GenerateConstructionVTab
>    assert(!VTable->isDeclaration() && "Shouldn't set properties on
> declaration");
>    CGM.setGVProperties(VTable, RD);
>
> -  CGM.EmitVTableTypeMetadata(RD, VTable, *VTLayout.get());
> +  CGM.EmitVTableTypeMetadata(VTable, *VTLayout.get());
>
>    return VTable;
>  }
> @@ -1039,32 +1039,7 @@ bool CodeGenModule::HasHiddenLTOVisibili
>    return true;
>  }
>
> -llvm::GlobalObject::VCallVisibility
> -CodeGenModule::GetVCallVisibilityLevel(const CXXRecordDecl *RD) {
> -  LinkageInfo LV = RD->getLinkageAndVisibility();
> -  llvm::GlobalObject::VCallVisibility TypeVis;
> -  if (!isExternallyVisible(LV.getLinkage()))
> -    TypeVis = llvm::GlobalObject::VCallVisibilityTranslationUnit;
> -  else if (HasHiddenLTOVisibility(RD))
> -    TypeVis = llvm::GlobalObject::VCallVisibilityLinkageUnit;
> -  else
> -    TypeVis = llvm::GlobalObject::VCallVisibilityPublic;
> -
> -  for (auto B : RD->bases())
> -    if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
> -      TypeVis = std::min(TypeVis,
> -
> GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl()));
> -
> -  for (auto B : RD->vbases())
> -    if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
> -      TypeVis = std::min(TypeVis,
> -
> GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl()));
> -
> -  return TypeVis;
> -}
> -
> -void CodeGenModule::EmitVTableTypeMetadata(const CXXRecordDecl *RD,
> -                                           llvm::GlobalVariable *VTable,
> +void CodeGenModule::EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
>                                             const VTableLayout &VTLayout) {
>    if (!getCodeGenOpts().LTOUnit)
>      return;
> @@ -1124,10 +1099,4 @@ void CodeGenModule::EmitVTableTypeMetada
>        VTable->addTypeMetadata((PointerWidth * I).getQuantity(), MD);
>      }
>    }
> -
> -  if (getCodeGenOpts().VirtualFunctionElimination) {
> -    llvm::GlobalObject::VCallVisibility TypeVis =
> GetVCallVisibilityLevel(RD);
> -    if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
> -      VTable->addVCallVisibilityMetadata(TypeVis);
> -  }
>  }
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Oct 14 16:25:25 2019
> @@ -1280,16 +1280,8 @@ public:
>    /// optimization.
>    bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
>
> -  /// Returns the vcall visibility of the given type. This is the scope
> in which
> -  /// 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.
> -  llvm::GlobalObject::VCallVisibility
> -  GetVCallVisibilityLevel(const CXXRecordDecl *RD);
> -
>    /// Emit type metadata for the given vtable using the given layout.
> -  void EmitVTableTypeMetadata(const CXXRecordDecl *RD,
> -                              llvm::GlobalVariable *VTable,
> +  void EmitVTableTypeMetadata(llvm::GlobalVariable *VTable,
>                                const VTableLayout &VTLayout);
>
>    /// Generate a cross-DSO type identifier for MD.
>
> Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
> +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Mon Oct 14 16:25:25 2019
> @@ -644,6 +644,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMember
>      VTableOffset = Builder.CreateTrunc(VTableOffset, CGF.Int32Ty);
>      VTableOffset = Builder.CreateZExt(VTableOffset, CGM.PtrDiffTy);
>    }
> +  // Compute the address of the virtual function pointer.
> +  llvm::Value *VFPAddr = Builder.CreateGEP(VTable, VTableOffset);
>
>    // Check the address of the function pointer if CFI on member function
>    // pointers is enabled.
> @@ -651,81 +653,44 @@ CGCallee ItaniumCXXABI::EmitLoadOfMember
>    llvm::Constant *CheckTypeDesc;
>    bool ShouldEmitCFICheck = CGF.SanOpts.has(SanitizerKind::CFIMFCall) &&
>                              CGM.HasHiddenLTOVisibility(RD);
> -  bool ShouldEmitVFEInfo =
> CGM.getCodeGenOpts().VirtualFunctionElimination &&
> -                           CGM.HasHiddenLTOVisibility(RD);
> -  llvm::Value *VirtualFn = nullptr;
> -
> -  {
> +  if (ShouldEmitCFICheck) {
>      CodeGenFunction::SanitizerScope SanScope(&CGF);
> -    llvm::Value *TypeId = nullptr;
> -    llvm::Value *CheckResult = nullptr;
>
> -    if (ShouldEmitCFICheck || ShouldEmitVFEInfo) {
> -      // If doing CFI or VFE, we will need the metadata node to check
> against.
> -      llvm::Metadata *MD =
> -          CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT,
> 0));
> -      TypeId = llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD);
> -    }
> +    CheckSourceLocation = CGF.EmitCheckSourceLocation(E->getBeginLoc());
> +    CheckTypeDesc = CGF.EmitCheckTypeDescriptor(QualType(MPT, 0));
> +    llvm::Constant *StaticData[] = {
> +        llvm::ConstantInt::get(CGF.Int8Ty,
> CodeGenFunction::CFITCK_VMFCall),
> +        CheckSourceLocation,
> +        CheckTypeDesc,
> +    };
> +
> +    llvm::Metadata *MD =
> +        CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT,
> 0));
> +    llvm::Value *TypeId =
> llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD);
>
> -    llvm::Value *VFPAddr = Builder.CreateGEP(VTable, VTableOffset);
> +    llvm::Value *TypeTest = Builder.CreateCall(
> +        CGM.getIntrinsic(llvm::Intrinsic::type_test), {VFPAddr, TypeId});
>
> -    if (ShouldEmitVFEInfo) {
> -      // If doing VFE, load from the vtable with a type.checked.load
> intrinsic
> -      // call. Note that we use the GEP to calculate the address to load
> from
> -      // and pass 0 as the offset to the intrinsic. This is because every
> -      // vtable slot of the correct type is marked with matching
> metadata, and
> -      // we know that the load must be from one of these slots.
> -      llvm::Value *CheckedLoad = Builder.CreateCall(
> -          CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
> -          {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId});
> -      CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
> -      VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0);
> -      VirtualFn = Builder.CreateBitCast(VirtualFn, FTy->getPointerTo(),
> -                                        "memptr.virtualfn");
> +    if (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) {
> +      CGF.EmitTrapCheck(TypeTest);
>      } else {
> -      // When not doing VFE, emit a normal load, as it allows more
> -      // optimisations than type.checked.load.
> -      if (ShouldEmitCFICheck) {
> -        CheckResult = Builder.CreateCall(
> -            CGM.getIntrinsic(llvm::Intrinsic::type_test),
> -            {Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId});
> -      }
> -      VFPAddr =
> -          Builder.CreateBitCast(VFPAddr,
> FTy->getPointerTo()->getPointerTo());
> -      VirtualFn = Builder.CreateAlignedLoad(VFPAddr,
> CGF.getPointerAlign(),
> -                                            "memptr.virtualfn");
> +      llvm::Value *AllVtables = llvm::MetadataAsValue::get(
> +          CGM.getLLVMContext(),
> +          llvm::MDString::get(CGM.getLLVMContext(), "all-vtables"));
> +      llvm::Value *ValidVtable = Builder.CreateCall(
> +          CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable,
> AllVtables});
> +      CGF.EmitCheck(std::make_pair(TypeTest, SanitizerKind::CFIMFCall),
> +                    SanitizerHandler::CFICheckFail, StaticData,
> +                    {VTable, ValidVtable});
>      }
> -    assert(VirtualFn && "Virtual fuction pointer not created!");
> -    assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || CheckResult) &&
> -           "Check result required but not created!");
> -
> -    if (ShouldEmitCFICheck) {
> -      // If doing CFI, emit the check.
> -      CheckSourceLocation = CGF.EmitCheckSourceLocation(E->getBeginLoc());
> -      CheckTypeDesc = CGF.EmitCheckTypeDescriptor(QualType(MPT, 0));
> -      llvm::Constant *StaticData[] = {
> -          llvm::ConstantInt::get(CGF.Int8Ty,
> CodeGenFunction::CFITCK_VMFCall),
> -          CheckSourceLocation,
> -          CheckTypeDesc,
> -      };
> -
> -      if
> (CGM.getCodeGenOpts().SanitizeTrap.has(SanitizerKind::CFIMFCall)) {
> -        CGF.EmitTrapCheck(CheckResult);
> -      } else {
> -        llvm::Value *AllVtables = llvm::MetadataAsValue::get(
> -            CGM.getLLVMContext(),
> -            llvm::MDString::get(CGM.getLLVMContext(), "all-vtables"));
> -        llvm::Value *ValidVtable = Builder.CreateCall(
> -            CGM.getIntrinsic(llvm::Intrinsic::type_test), {VTable,
> AllVtables});
> -        CGF.EmitCheck(std::make_pair(CheckResult,
> SanitizerKind::CFIMFCall),
> -                      SanitizerHandler::CFICheckFail, StaticData,
> -                      {VTable, ValidVtable});
> -      }
>
> -      FnVirtual = Builder.GetInsertBlock();
> -    }
> -  } // End of sanitizer scope
> +    FnVirtual = Builder.GetInsertBlock();
> +  }
>
> +  // Load the virtual function to call.
> +  VFPAddr = Builder.CreateBitCast(VFPAddr,
> FTy->getPointerTo()->getPointerTo());
> +  llvm::Value *VirtualFn = Builder.CreateAlignedLoad(
> +      VFPAddr, CGF.getPointerAlign(), "memptr.virtualfn");
>    CGF.EmitBranch(FnEnd);
>
>    // In the non-virtual path, the function pointer is actually a
> @@ -1669,7 +1634,7 @@ void ItaniumCXXABI::emitVTableDefinition
>      EmitFundamentalRTTIDescriptors(RD);
>
>    if (!VTable->isDeclarationForLinker())
> -    CGM.EmitVTableTypeMetadata(RD, VTable, VTLayout);
> +    CGM.EmitVTableTypeMetadata(VTable, VTLayout);
>  }
>
>  bool ItaniumCXXABI::isVirtualOffsetNeededForVTableField(
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Oct 14 16:25:25 2019
> @@ -5366,30 +5366,9 @@ void Clang::ConstructJob(Compilation &C,
>      CmdArgs.push_back(Args.MakeArgString(TargetInfo.str()));
>    }
>
> -  bool VirtualFunctionElimination =
> -      Args.hasFlag(options::OPT_fvirtual_function_elimination,
> -                   options::OPT_fno_virtual_function_elimination, false);
> -  if (VirtualFunctionElimination) {
> -    // VFE requires full LTO (currently, this might be relaxed to allow
> ThinLTO
> -    // in the future).
> -    if (D.getLTOMode() != LTOK_Full)
> -      D.Diag(diag::err_drv_argument_only_allowed_with)
> -          << "-fvirtual-function-elimination"
> -          << "-flto=full";
> -
> -    CmdArgs.push_back("-fvirtual-function-elimination");
> -  }
> -
> -  // VFE requires whole-program-vtables, and enables it by default.
> -  bool WholeProgramVTables = Args.hasFlag(
> -      options::OPT_fwhole_program_vtables,
> -      options::OPT_fno_whole_program_vtables, VirtualFunctionElimination);
> -  if (VirtualFunctionElimination && !WholeProgramVTables) {
> -    D.Diag(diag::err_drv_argument_not_allowed_with)
> -        << "-fno-whole-program-vtables"
> -        << "-fvirtual-function-elimination";
> -  }
> -
> +  bool WholeProgramVTables =
> +      Args.hasFlag(options::OPT_fwhole_program_vtables,
> +                   options::OPT_fno_whole_program_vtables, false);
>    if (WholeProgramVTables) {
>      if (!D.isUsingLTO())
>        D.Diag(diag::err_drv_argument_only_allowed_with)
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=374844&r1=374843&r2=374844&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Oct 14 16:25:25 2019
> @@ -758,8 +758,6 @@ static bool ParseCodeGenArgs(CodeGenOpti
>    Opts.CodeViewGHash = Args.hasArg(OPT_gcodeview_ghash);
>    Opts.MacroDebugInfo = Args.hasArg(OPT_debug_info_macro);
>    Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
> -  Opts.VirtualFunctionElimination =
> -      Args.hasArg(OPT_fvirtual_function_elimination);
>    Opts.LTOVisibilityPublicStd =
> Args.hasArg(OPT_flto_visibility_public_std);
>    Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
>    Opts.SplitDwarfOutput = Args.getLastArgValue(OPT_split_dwarf_output);
>
> Removed: cfe/trunk/test/CodeGenCXX/vcall-visibility-metadata.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vcall-visibility-metadata.cpp?rev=374843&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/vcall-visibility-metadata.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/vcall-visibility-metadata.cpp (removed)
> @@ -1,88 +0,0 @@
> -// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux
> -emit-llvm -fvirtual-function-elimination -fwhole-program-vtables -o - %s |
> FileCheck %s
> -
> -
> -// Anonymous namespace.
> -namespace {
> -// CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility
> [[VIS_TU:![0-9]+]]
> -struct A {
> -  A() {}
> -  virtual int f() { return 1; }
> -};
> -}
> -void *construct_A() {
> -  return new A();
> -}
> -
> -
> -// Hidden visibility.
> -// CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
> -struct __attribute__((visibility("hidden"))) B {
> -  B() {}
> -  virtual int f() { return 1; }
> -};
> -B *construct_B() {
> -  return new B();
> -}
> -
> -
> -// Default visibility.
> -// CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
> -struct __attribute__((visibility("default"))) C {
> -  C() {}
> -  virtual int f() { return 1; }
> -};
> -C *construct_C() {
> -  return new C();
> -}
> -
> -
> -// Hidden visibility, public LTO visibility.
> -// CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
> -struct __attribute__((visibility("hidden")))
> [[clang::lto_visibility_public]] D {
> -  D() {}
> -  virtual int f() { return 1; }
> -};
> -D *construct_D() {
> -  return new D();
> -}
> -
> -
> -// Hidden visibility, but inherits from class with default visibility.
> -// CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
> -struct __attribute__((visibility("hidden"))) E : C {
> -  E() {}
> -  virtual int f() { return 1; }
> -};
> -E *construct_E() {
> -  return new E();
> -}
> -
> -
> -// Anonymous namespace, but inherits from class with default visibility.
> -// CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
> -namespace {
> -struct __attribute__((visibility("hidden"))) F : C {
> -  F() {}
> -  virtual int f() { return 1; }
> -};
> -}
> -void *construct_F() {
> -  return new F();
> -}
> -
> -
> -// Anonymous namespace, but inherits from class with hidden visibility.
> -// CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility
> [[VIS_DSO:![0-9]+]]
> -namespace {
> -struct __attribute__((visibility("hidden"))) G : B {
> -  G() {}
> -  virtual int f() { return 1; }
> -};
> -}
> -void *construct_G() {
> -  return new G();
> -}
> -
> -
> -// CHECK-DAG: [[VIS_DSO]] = !{i64 1}
> -// CHECK-DAG: [[VIS_TU]] = !{i64 2}
>
> Removed: cfe/trunk/test/CodeGenCXX/virtual-function-elimination.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-function-elimination.cpp?rev=374843&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/virtual-function-elimination.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/virtual-function-elimination.cpp (removed)
> @@ -1,75 +0,0 @@
> -// RUN: %clang_cc1 -triple x86_64-unknown-linux -flto -flto-unit
> -fvirtual-function-elimination -fwhole-program-vtables -emit-llvm -o - %s |
> FileCheck %s
> -
> -
> -struct __attribute__((visibility("default"))) A {
> -  virtual void foo();
> -};
> -
> -void test_1(A *p) {
> -  // A has default visibility, so no need for type.checked.load.
> -// CHECK-LABEL: define void @_Z6test_1P1A
> -// CHECK: [[FN_PTR_ADDR:%.+]] = getelementptr inbounds void
> (%struct.A*)*, void (%struct.A*)** {{%.+}}, i64 0
> -// CHECK: [[FN_PTR:%.+]] = load void (%struct.A*)*, void (%struct.A*)**
> [[FN_PTR_ADDR]]
> -// CHECK: call void [[FN_PTR]](
> -  p->foo();
> -}
> -
> -
> -struct __attribute__((visibility("hidden")))
> [[clang::lto_visibility_public]] B {
> -  virtual void foo();
> -};
> -
> -void test_2(B *p) {
> -  // B has public LTO visibility, so no need for type.checked.load.
> -// CHECK-LABEL: define void @_Z6test_2P1B
> -// CHECK: [[FN_PTR_ADDR:%.+]] = getelementptr inbounds void
> (%struct.B*)*, void (%struct.B*)** {{%.+}}, i64 0
> -// CHECK: [[FN_PTR:%.+]] = load void (%struct.B*)*, void (%struct.B*)**
> [[FN_PTR_ADDR]]
> -// CHECK: call void [[FN_PTR]](
> -  p->foo();
> -}
> -
> -
> -struct __attribute__((visibility("hidden"))) C {
> -  virtual void foo();
> -  virtual void bar();
> -};
> -
> -void test_3(C *p) {
> -  // C has hidden visibility, so we generate type.checked.load to allow
> VFE.
> -// CHECK-LABEL: define void @_Z6test_3P1C
> -// CHECK: [[LOAD:%.+]] = call { i8*, i1 } @llvm.type.checked.load(i8*
> {{%.+}}, i32 0, metadata !"_ZTS1C")
> -// CHECK: [[FN_PTR_I8:%.+]] = extractvalue { i8*, i1 } [[LOAD]], 0
> -// CHECK: [[FN_PTR:%.+]] = bitcast i8* [[FN_PTR_I8]] to void (%struct.C*)*
> -// CHECK: call void [[FN_PTR]](
> -  p->foo();
> -}
> -
> -void test_4(C *p) {
> -  // When using type.checked.load, we pass the vtable offset to the
> intrinsic,
> -  // rather than adding it to the pointer with a GEP.
> -// CHECK-LABEL: define void @_Z6test_4P1C
> -// CHECK: [[LOAD:%.+]] = call { i8*, i1 } @llvm.type.checked.load(i8*
> {{%.+}}, i32 8, metadata !"_ZTS1C")
> -// CHECK: [[FN_PTR_I8:%.+]] = extractvalue { i8*, i1 } [[LOAD]], 0
> -// CHECK: [[FN_PTR:%.+]] = bitcast i8* [[FN_PTR_I8]] to void (%struct.C*)*
> -// CHECK: call void [[FN_PTR]](
> -  p->bar();
> -}
> -
> -void test_5(C *p, void (C::*q)(void)) {
> -  // We also use type.checked.load for the virtual side of member function
> -  // pointer calls. We use a GEP to calculate the address to load from
> and pass
> -  // 0 as the offset to the intrinsic, because we know that the load must
> be
> -  // from exactly the point marked by one of the function-type metadatas
> (in
> -  // this case "_ZTSM1CFvvE.virtual"). If we passed the offset from the
> member
> -  // function pointer to the intrinsic, this information would be lost. No
> -  // codegen changes on the non-virtual side.
> -// CHECK-LABEL: define void @_Z6test_5P1CMS_FvvE(
> -// CHECK: [[FN_PTR_ADDR:%.+]] = getelementptr i8, i8* %vtable, i64 {{%.+}}
> -// CHECK: [[LOAD:%.+]] = call { i8*, i1 } @llvm.type.checked.load(i8*
> [[FN_PTR_ADDR]], i32 0, metadata !"_ZTSM1CFvvE.virtual")
> -// CHECK: [[FN_PTR_I8:%.+]] = extractvalue { i8*, i1 } [[LOAD]], 0
> -// CHECK: [[FN_PTR:%.+]] = bitcast i8* [[FN_PTR_I8]] to void (%struct.C*)*
> -
> -// CHECK: [[PHI:%.+]] = phi void (%struct.C*)* {{.*}}[ [[FN_PTR]], {{.*}}
> ]
> -// CHECK: call void [[PHI]](
> -  (p->*q)();
> -}
>
> Removed: cfe/trunk/test/Driver/virtual-function-elimination.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/virtual-function-elimination.cpp?rev=374843&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Driver/virtual-function-elimination.cpp (original)
> +++ cfe/trunk/test/Driver/virtual-function-elimination.cpp (removed)
> @@ -1,11 +0,0 @@
> -// RUN: %clang -target x86_64-unknown-linux
> -fvirtual-function-elimination -### %s 2>&1 | FileCheck
> --check-prefix=BAD-LTO %s
> -// RUN: %clang -target x86_64-unknown-linux
> -fvirtual-function-elimination -flto=thin -### %s 2>&1 | FileCheck
> --check-prefix=BAD-LTO %s
> -// BAD-LTO: invalid argument '-fvirtual-function-elimination' only
> allowed with '-flto=full'
> -
> -// RUN: %clang -target x86_64-unknown-linux
> -fvirtual-function-elimination -flto -### %s 2>&1 | FileCheck
> --check-prefix=GOOD %s
> -// RUN: %clang -target x86_64-unknown-linux
> -fvirtual-function-elimination -flto=full -### %s 2>&1 | FileCheck
> --check-prefix=GOOD %s
> -// RUN: %clang -target x86_64-unknown-linux
> -fvirtual-function-elimination -flto -fwhole-program-vtables -### %s 2>&1 |
> FileCheck --check-prefix=GOOD %s
> -// GOOD: "-fvirtual-function-elimination" "-fwhole-program-vtables"
> -
> -// RUN: %clang -target x86_64-unknown-linux
> -fvirtual-function-elimination -fno-whole-program-vtables -flto -### %s
> 2>&1 | FileCheck --check-prefix=NO-WHOLE-PROGRAM-VTABLES %s
> -// NO-WHOLE-PROGRAM-VTABLES: invalid argument
> '-fno-whole-program-vtables' not allowed with
> '-fvirtual-function-elimination'
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191014/26d2825b/attachment-0001.html>


More information about the cfe-commits mailing list