Skip to content

Commit 90e630a

Browse files
committed
Revert "[LTO/WPD] Enable aggressive WPD under LTO option"
This reverts commit 5973352. 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
1 parent 69bf40c commit 90e630a

File tree

71 files changed

+93
-1046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+93
-1046
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "llvm/Transforms/Coroutines.h"
5252
#include "llvm/Transforms/IPO.h"
5353
#include "llvm/Transforms/IPO/AlwaysInliner.h"
54-
#include "llvm/Transforms/IPO/LowerTypeTests.h"
5554
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
5655
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
5756
#include "llvm/Transforms/InstCombine/InstCombine.h"
@@ -554,16 +553,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
554553
std::unique_ptr<TargetLibraryInfoImpl> TLII(
555554
createTLII(TargetTriple, CodeGenOpts));
556555

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

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

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

1173-
// If we reached here with a non-empty index file name, then the index
1174-
// file was empty and we are not performing ThinLTO backend compilation
1175-
// (used in testing in a distributed build environment). Drop any the type
1176-
// test assume sequences inserted for whole program vtables so that
1177-
// codegen doesn't complain.
1178-
if (!CodeGenOpts.ThinLTOIndexFile.empty())
1179-
PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
1180-
MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
1181-
/*ImportSummary=*/nullptr,
1182-
/*DropTypeTests=*/true));
1183-
});
1184-
11851153
PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
11861154
MPM.addPass(createModuleToFunctionPassAdaptor(
11871155
EntryExitInstrumenterPass(/*PostInlining=*/false)));

clang/lib/CodeGen/CGClass.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,9 +2641,7 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
26412641
if (SanOpts.has(SanitizerKind::CFIVCall))
26422642
EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
26432643
else if (CGM.getCodeGenOpts().WholeProgramVTables &&
2644-
// Don't insert type test assumes if we are forcing public std
2645-
// visibility.
2646-
!CGM.HasLTOVisibilityPublicStd(RD)) {
2644+
CGM.HasHiddenLTOVisibility(RD)) {
26472645
llvm::Metadata *MD =
26482646
CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
26492647
llvm::Value *TypeId =

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,26 +1011,6 @@ void CodeGenModule::EmitDeferredVTables() {
10111011
DeferredVTables.clear();
10121012
}
10131013

1014-
bool CodeGenModule::HasLTOVisibilityPublicStd(const CXXRecordDecl *RD) {
1015-
if (!getCodeGenOpts().LTOVisibilityPublicStd)
1016-
return false;
1017-
1018-
const DeclContext *DC = RD;
1019-
while (1) {
1020-
auto *D = cast<Decl>(DC);
1021-
DC = DC->getParent();
1022-
if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
1023-
if (auto *ND = dyn_cast<NamespaceDecl>(D))
1024-
if (const IdentifierInfo *II = ND->getIdentifier())
1025-
if (II->isStr("std") || II->isStr("stdext"))
1026-
return true;
1027-
break;
1028-
}
1029-
}
1030-
1031-
return false;
1032-
}
1033-
10341014
bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
10351015
LinkageInfo LV = RD->getLinkageAndVisibility();
10361016
if (!isExternallyVisible(LV.getLinkage()))
@@ -1047,7 +1027,22 @@ bool CodeGenModule::HasHiddenLTOVisibility(const CXXRecordDecl *RD) {
10471027
return false;
10481028
}
10491029

1050-
return !HasLTOVisibilityPublicStd(RD);
1030+
if (getCodeGenOpts().LTOVisibilityPublicStd) {
1031+
const DeclContext *DC = RD;
1032+
while (1) {
1033+
auto *D = cast<Decl>(DC);
1034+
DC = DC->getParent();
1035+
if (isa<TranslationUnitDecl>(DC->getRedeclContext())) {
1036+
if (auto *ND = dyn_cast<NamespaceDecl>(D))
1037+
if (const IdentifierInfo *II = ND->getIdentifier())
1038+
if (II->isStr("std") || II->isStr("stdext"))
1039+
return false;
1040+
break;
1041+
}
1042+
}
1043+
}
1044+
1045+
return true;
10511046
}
10521047

10531048
llvm::GlobalObject::VCallVisibility

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,11 +1292,6 @@ class CodeGenModule : public CodeGenTypeCache {
12921292
/// optimization.
12931293
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
12941294

1295-
/// Returns whether the given record has public std LTO visibility
1296-
/// and therefore may not participate in (single-module) CFI and whole-program
1297-
/// vtable optimization.
1298-
bool HasLTOVisibilityPublicStd(const CXXRecordDecl *RD);
1299-
13001295
/// Returns the vcall visibility of the given type. This is the scope in which
13011296
/// a virtual function call could be made which ends up being dispatched to a
13021297
/// member function of this class. This scope can be wider than the visibility

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,20 +670,15 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
670670
CGM.HasHiddenLTOVisibility(RD);
671671
bool ShouldEmitVFEInfo = CGM.getCodeGenOpts().VirtualFunctionElimination &&
672672
CGM.HasHiddenLTOVisibility(RD);
673-
bool ShouldEmitWPDInfo =
674-
CGM.getCodeGenOpts().WholeProgramVTables &&
675-
// Don't insert type tests if we are forcing public std visibility.
676-
!CGM.HasLTOVisibilityPublicStd(RD);
677673
llvm::Value *VirtualFn = nullptr;
678674

679675
{
680676
CodeGenFunction::SanitizerScope SanScope(&CGF);
681677
llvm::Value *TypeId = nullptr;
682678
llvm::Value *CheckResult = nullptr;
683679

684-
if (ShouldEmitCFICheck || ShouldEmitVFEInfo || ShouldEmitWPDInfo) {
685-
// If doing CFI, VFE or WPD, we will need the metadata node to check
686-
// against.
680+
if (ShouldEmitCFICheck || ShouldEmitVFEInfo) {
681+
// If doing CFI or VFE, we will need the metadata node to check against.
687682
llvm::Metadata *MD =
688683
CGM.CreateMetadataIdentifierForVirtualMemPtrType(QualType(MPT, 0));
689684
TypeId = llvm::MetadataAsValue::get(CGF.getLLVMContext(), MD);
@@ -707,7 +702,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
707702
} else {
708703
// When not doing VFE, emit a normal load, as it allows more
709704
// optimisations than type.checked.load.
710-
if (ShouldEmitCFICheck || ShouldEmitWPDInfo) {
705+
if (ShouldEmitCFICheck) {
711706
CheckResult = Builder.CreateCall(
712707
CGM.getIntrinsic(llvm::Intrinsic::type_test),
713708
{Builder.CreateBitCast(VFPAddr, CGF.Int8PtrTy), TypeId});
@@ -718,8 +713,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
718713
"memptr.virtualfn");
719714
}
720715
assert(VirtualFn && "Virtual fuction pointer not created!");
721-
assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || !ShouldEmitWPDInfo ||
722-
CheckResult) &&
716+
assert((!ShouldEmitCFICheck || !ShouldEmitVFEInfo || CheckResult) &&
723717
"Check result required but not created!");
724718

725719
if (ShouldEmitCFICheck) {

clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436.
1010
; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
11-
; RUN: -whole-program-visibility \
1211
; RUN: -verify-machineinstrs=0 \
1312
; RUN: -o %t2.index \
1413
; RUN: -r=%t.o,test,px \

clang/test/CodeGenCXX/cfi-mfcall.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-mfcall -fsanitize-trap=cfi-mfcall -fvisibility hidden -emit-llvm -o - %s | FileCheck %s
22
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-mfcall -fsanitize-trap=cfi-mfcall -fvisibility default -emit-llvm -o - %s | FileCheck --check-prefix=DEFAULT %s
3-
// With -fwhole-program-vtables we should get the member function pointer type
4-
// test, even without hidden visibility.
5-
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck %s --check-prefix=WPV
63

74
struct B1 {};
85
struct B2 {};
@@ -12,9 +9,6 @@ struct S : B1, B3 {};
129
// DEFAULT-NOT: llvm.type.test
1310

1411
void f(S *s, void (S::*p)()) {
15-
// WPV: [[OFFSET:%.*]] = sub i64 {{.*}}, 1
16-
// WPV: [[VFPTR:%.*]] = getelementptr i8, i8* %{{.*}}, i64 [[OFFSET]]
17-
// WPV: [[TT:%.*]] = call i1 @llvm.type.test(i8* [[VFPTR]], metadata !"_ZTSM1SFvvE.virtual")
1812
// CHECK: [[OFFSET:%.*]] = sub i64 {{.*}}, 1
1913
// CHECK: [[VFPTR:%.*]] = getelementptr i8, i8* %{{.*}}, i64 [[OFFSET]]
2014
// CHECK: [[TT:%.*]] = call i1 @llvm.type.test(i8* [[VFPTR]], metadata !"_ZTSM1SFvvE.virtual")

clang/test/CodeGenCXX/lto-visibility-inference.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ void f(C1 *c1, C2 *c2, C3 *c3, C4 *c4, C5 *c5, C6 *c6, std::C7 *c7,
7070
// ITANIUM: type.test{{.*}}!"_ZTS2C1"
7171
// MS: type.test{{.*}}!"?AUC1@@"
7272
c1->f();
73-
// ITANIUM: type.test{{.*}}!"_ZTS2C2"
73+
// ITANIUM-NOT: type.test{{.*}}!"_ZTS2C2"
7474
// MS: type.test{{.*}}!"?AUC2@@"
7575
c2->f();
7676
// ITANIUM: type.test{{.*}}!"_ZTS2C3"
77-
// MS: type.test{{.*}}!"?AUC3@@"
77+
// MS-NOT: type.test{{.*}}!"?AUC3@@"
7878
c3->f();
7979
// ITANIUM: type.test{{.*}}!"_ZTS2C4"
80-
// MS: type.test{{.*}}!"?AUC4@@"
80+
// MS-NOT: type.test{{.*}}!"?AUC4@@"
8181
c4->f();
82-
// ITANIUM: type.test{{.*}}!"_ZTS2C5"
83-
// MS: type.test{{.*}}!"?AUC5@@"
82+
// ITANIUM-NOT: type.test{{.*}}!"_ZTS2C5"
83+
// MS-NOT: type.test{{.*}}!"?AUC5@@"
8484
c5->f();
85-
// ITANIUM: type.test{{.*}}!"_ZTS2C6"
86-
// MS: type.test{{.*}}!"?AUC6@@"
85+
// ITANIUM-NOT: type.test{{.*}}!"_ZTS2C6"
86+
// MS-NOT: type.test{{.*}}!"?AUC6@@"
8787
c6->f();
8888
// ITANIUM: type.test{{.*}}!"_ZTSSt2C7"
8989
// MS-STD: type.test{{.*}}!"?AUC7@std@@"

clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp

Lines changed: 0 additions & 69 deletions
This file was deleted.

clang/test/CodeGenCXX/type-metadata.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
// Tests for the whole-program-vtables feature:
88
// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fvisibility hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM --check-prefix=TT-ITANIUM %s
9-
// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=ITANIUM-DEFAULTVIS --check-prefix=TT-ITANIUM %s
109
// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=MS --check-prefix=TT-MS %s
1110

1211
// Tests for cfi + whole-program-vtables:
@@ -130,7 +129,6 @@ void D::h() {
130129
}
131130

132131
// ITANIUM: define hidden void @_Z2afP1A
133-
// ITANIUM-DEFAULTVIS: define void @_Z2afP1A
134132
// MS: define dso_local void @"?af@@YAXPEAUA@@@Z"
135133
void af(A *a) {
136134
// TT-ITANIUM: [[P:%[^ ]*]] = call i1 @llvm.type.test(i8* [[VT:%[^ ]*]], metadata !"_ZTS1A")
@@ -241,7 +239,6 @@ struct D : C {
241239
};
242240

243241
// ITANIUM: define hidden void @_ZN5test21fEPNS_1DE
244-
// ITANIUM-DEFAULTVIS: define void @_ZN5test21fEPNS_1DE
245242
// MS: define dso_local void @"?f@test2@@YAXPEAUD@1@@Z"
246243
void f(D *d) {
247244
// TT-ITANIUM: {{%[^ ]*}} = call i1 @llvm.type.test(i8* {{%[^ ]*}}, metadata !"_ZTSN5test21DE")

lld/ELF/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ struct Configuration {
165165
bool ltoCSProfileGenerate;
166166
bool ltoDebugPassManager;
167167
bool ltoNewPassManager;
168-
bool ltoWholeProgramVisibility;
169168
bool mergeArmExidx;
170169
bool mipsN32Abi = false;
171170
bool mmapOutputFile;

lld/ELF/Driver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,6 @@ static void readConfigs(opt::InputArgList &args) {
899899
config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
900900
config->ltoNewPassManager = args.hasArg(OPT_lto_new_pass_manager);
901901
config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
902-
config->ltoWholeProgramVisibility =
903-
args.hasArg(OPT_lto_whole_program_visibility);
904902
config->ltoo = args::getInteger(args, OPT_lto_O, 2);
905903
config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
906904
config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);

lld/ELF/LTO.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ static lto::Config createConfig() {
111111
c.DebugPassManager = config->ltoDebugPassManager;
112112
c.DwoDir = config->dwoDir;
113113

114-
c.HasWholeProgramVisibility = config->ltoWholeProgramVisibility;
115-
116114
c.CSIRProfile = config->ltoCSProfileFile;
117115
c.RunCSIRInstr = config->ltoCSProfileGenerate;
118116

lld/ELF/Options.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,6 @@ def lto_cs_profile_file: J<"lto-cs-profile-file=">,
479479
def lto_obj_path_eq: J<"lto-obj-path=">;
480480
def lto_sample_profile: J<"lto-sample-profile=">,
481481
HelpText<"Sample profile file path">;
482-
def lto_whole_program_visibility: F<"lto-whole-program-visibility">,
483-
HelpText<"Asserts that the LTO link has whole program visibility">;
484482
def disable_verify: F<"disable-verify">;
485483
defm mllvm: Eq<"mllvm", "Additional arguments to forward to LLVM's option processing">;
486484
def opt_remarks_filename: Separate<["--"], "opt-remarks-filename">,

0 commit comments

Comments
 (0)