Commit 90e630a9 authored by Teresa Johnson's avatar Teresa Johnson
Browse files

Revert "[LTO/WPD] Enable aggressive WPD under LTO option"

This reverts commit 59733525.

There is a windows sanitizer bot failure in one of the cfi tests
that I will need some time to figure out:
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/57155/steps/stage%201%20check/logs/stdio
parent 69bf40c4
Loading
Loading
Loading
Loading
+0 −32
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@
#include "llvm/Transforms/Coroutines.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/LowerTypeTests.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
@@ -554,16 +553,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
  std::unique_ptr<TargetLibraryInfoImpl> TLII(
      createTLII(TargetTriple, CodeGenOpts));

  // If we reached here with a non-empty index file name, then the index file
  // was empty and we are not performing ThinLTO backend compilation (used in
  // testing in a distributed build environment). Drop any the type test
  // assume sequences inserted for whole program vtables so that codegen doesn't
  // complain.
  if (!CodeGenOpts.ThinLTOIndexFile.empty())
    MPM.add(createLowerTypeTestsPass(/*ExportSummary=*/nullptr,
                                     /*ImportSummary=*/nullptr,
                                     /*DropTypeTests=*/true));

  PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);

  // At O0 and O1 we only run the always inliner which is more efficient. At
@@ -1125,15 +1114,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
    bool IsLTO = CodeGenOpts.PrepareForLTO;

    if (CodeGenOpts.OptimizationLevel == 0) {
      // If we reached here with a non-empty index file name, then the index
      // file was empty and we are not performing ThinLTO backend compilation
      // (used in testing in a distributed build environment). Drop any the type
      // test assume sequences inserted for whole program vtables so that
      // codegen doesn't complain.
      if (!CodeGenOpts.ThinLTOIndexFile.empty())
        MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
                                       /*ImportSummary=*/nullptr,
                                       /*DropTypeTests=*/true));
      if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts))
        MPM.addPass(GCOVProfilerPass(*Options));
      if (Optional<InstrProfOptions> Options =
@@ -1170,18 +1150,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
      // configure the pipeline.
      PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);

      // If we reached here with a non-empty index file name, then the index
      // file was empty and we are not performing ThinLTO backend compilation
      // (used in testing in a distributed build environment). Drop any the type
      // test assume sequences inserted for whole program vtables so that
      // codegen doesn't complain.
      if (!CodeGenOpts.ThinLTOIndexFile.empty())
        PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
          MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
                                         /*ImportSummary=*/nullptr,
                                         /*DropTypeTests=*/true));
        });

      PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
        MPM.addPass(createModuleToFunctionPassAdaptor(
            EntryExitInstrumenterPass(/*PostInlining=*/false)));
+1 −3
Original line number Diff line number Diff line
@@ -2641,9 +2641,7 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
  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 std
           // visibility.
           !CGM.HasLTOVisibilityPublicStd(RD)) {
           CGM.HasHiddenLTOVisibility(RD)) {
    llvm::Metadata *MD =
        CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
    llvm::Value *TypeId =
+16 −21
Original line number Diff line number Diff line
@@ -1011,26 +1011,6 @@ void CodeGenModule::EmitDeferredVTables() {
  DeferredVTables.clear();
}

bool CodeGenModule::HasLTOVisibilityPublicStd(const CXXRecordDecl *RD) {
  if (!getCodeGenOpts().LTOVisibilityPublicStd)
    return false;

  const DeclContext *DC = RD;
  while (1) {
    auto *D = cast<Decl>(DC);
    DC = DC->getParent();
    if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
      if (auto *ND = dyn_cast<NamespaceDecl>(D))
        if (const IdentifierInfo *II = ND->getIdentifier())
          if (II->isStr("std") || II->isStr("stdext"))
            return true;
      break;
    }
  }

  return false;
}

bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
  LinkageInfo LV = RD->getLinkageAndVisibility();
  if (!isExternallyVisible(LV.getLinkage()))
@@ -1047,7 +1027,22 @@ bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
      return false;
  }

  return !HasLTOVisibilityPublicStd(RD);
  if (getCodeGenOpts().LTOVisibilityPublicStd) {
    const DeclContext *DC = RD;
    while (1) {
      auto *D = cast<Decl>(DC);
      DC = DC->getParent();
      if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
        if (auto *ND = dyn_cast<NamespaceDecl>(D))
          if (const IdentifierInfo *II = ND->getIdentifier())
            if (II->isStr("std") || II->isStr("stdext"))
              return false;
        break;
      }
    }
  }

  return true;
}

llvm::GlobalObject::VCallVisibility
+0 −5
Original line number Diff line number Diff line
@@ -1292,11 +1292,6 @@ public:
  /// optimization.
  bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);

  /// Returns whether the given record has public std LTO visibility
  /// and therefore may not participate in (single-module) CFI and whole-program
  /// vtable optimization.
  bool HasLTOVisibilityPublicStd(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
+4 −10
Original line number Diff line number Diff line
@@ -670,10 +670,6 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
                            CGM.HasHiddenLTOVisibility(RD);
  bool ShouldEmitVFEInfo = CGM.getCodeGenOpts().VirtualFunctionElimination &&
                           CGM.HasHiddenLTOVisibility(RD);
  bool ShouldEmitWPDInfo =
      CGM.getCodeGenOpts().WholeProgramVTables &&
      // Don't insert type tests if we are forcing public std visibility.
      !CGM.HasLTOVisibilityPublicStd(RD);
  llvm::Value *VirtualFn = nullptr;

  {
@@ -681,9 +677,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
    llvm::Value *TypeId = nullptr;
    llvm::Value *CheckResult = nullptr;

    if (ShouldEmitCFICheck || ShouldEmitVFEInfo || ShouldEmitWPDInfo) {
      // If doing CFI, VFE or WPD, we will need the metadata node to check
      // against.
    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);
@@ -707,7 +702,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
    } else {
      // When not doing VFE, emit a normal load, as it allows more
      // optimisations than type.checked.load.
      if (ShouldEmitCFICheck || ShouldEmitWPDInfo) {
      if (ShouldEmitCFICheck) {
        CheckResult = Builder.CreateCall(
            CGM.getIntrinsic(llvm::Intrinsic::type_test),
            {Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId});
@@ -718,8 +713,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
                                            "memptr.virtualfn");
    }
    assert(VirtualFn && "Virtual fuction pointer not created!");
    assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || !ShouldEmitWPDInfo ||
            CheckResult) &&
    assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || CheckResult) &&
           "Check result required but not created!");

    if (ShouldEmitCFICheck) {
Loading