@@ -122,6 +122,10 @@ static cl::opt<bool>
122
122
ClDropTypeTests (" lowertypetests-drop-type-tests" ,
123
123
cl::desc (" Simply drop type test assume sequences" ),
124
124
cl::Hidden, cl::init(false ));
125
+ static cl::opt<bool >
126
+ ClForceDropTypeTests (" lowertypetests-force-drop-type-tests" ,
127
+ cl::desc (" Always drop all type test sequences" ),
128
+ cl::Hidden, cl::init(false ));
125
129
126
130
bool BitSetInfo::containsGlobalOffset (uint64_t Offset) const {
127
131
if (Offset < ByteOffset)
@@ -400,6 +404,7 @@ class LowerTypeTestsModule {
400
404
// Set when the client has invoked this to simply drop all type test assume
401
405
// sequences.
402
406
bool DropTypeTests;
407
+ bool AlwaysDropTests;
403
408
404
409
Triple::ArchType Arch;
405
410
Triple::OSType OS;
@@ -542,7 +547,7 @@ class LowerTypeTestsModule {
542
547
LowerTypeTestsModule (Module &M, ModuleAnalysisManager &AM,
543
548
ModuleSummaryIndex *ExportSummary,
544
549
const ModuleSummaryIndex *ImportSummary,
545
- bool DropTypeTests);
550
+ bool DropTypeTests, bool AlwaysDropTests );
546
551
547
552
bool lower ();
548
553
@@ -1828,9 +1833,11 @@ void LowerTypeTestsModule::buildBitSetsFromDisjointSet(
1828
1833
// / Lower all type tests in this module.
1829
1834
LowerTypeTestsModule::LowerTypeTestsModule (
1830
1835
Module &M, ModuleAnalysisManager &AM, ModuleSummaryIndex *ExportSummary,
1831
- const ModuleSummaryIndex *ImportSummary, bool DropTypeTests)
1836
+ const ModuleSummaryIndex *ImportSummary, bool DropTypeTests,
1837
+ bool AlwaysDropTests)
1832
1838
: M(M), ExportSummary(ExportSummary), ImportSummary(ImportSummary),
1833
- DropTypeTests(DropTypeTests || ClDropTypeTests) {
1839
+ DropTypeTests(DropTypeTests || ClDropTypeTests),
1840
+ AlwaysDropTests(AlwaysDropTests || ClForceDropTypeTests) {
1834
1841
assert (!(ExportSummary && ImportSummary));
1835
1842
Triple TargetTriple (M.getTargetTriple ());
1836
1843
Arch = TargetTriple.getArch ();
@@ -1882,7 +1889,7 @@ bool LowerTypeTestsModule::runForTesting(Module &M, ModuleAnalysisManager &AM) {
1882
1889
M, AM,
1883
1890
ClSummaryAction == PassSummaryAction::Export ? &Summary : nullptr ,
1884
1891
ClSummaryAction == PassSummaryAction::Import ? &Summary : nullptr ,
1885
- /* DropTypeTests*/ false )
1892
+ /* DropTypeTests*/ false , /* AlwaysDropTests= */ false )
1886
1893
.lower ();
1887
1894
1888
1895
if (!ClWriteSummary.empty ()) {
@@ -1949,7 +1956,7 @@ void LowerTypeTestsModule::replaceDirectCalls(Value *Old, Value *New) {
1949
1956
Old->replaceUsesWithIf (New, isDirectCall);
1950
1957
}
1951
1958
1952
- static void dropTypeTests (Module &M, Function &TypeTestFunc) {
1959
+ static void dropTypeTests (Module &M, Function &TypeTestFunc, bool AlwaysDrop ) {
1953
1960
for (Use &U : llvm::make_early_inc_range (TypeTestFunc.uses ())) {
1954
1961
auto *CI = cast<CallInst>(U.getUser ());
1955
1962
// Find and erase llvm.assume intrinsics for this llvm.type.test call.
@@ -1960,8 +1967,9 @@ static void dropTypeTests(Module &M, Function &TypeTestFunc) {
1960
1967
// phi (which will feed the assume). Simply replace the use on the phi
1961
1968
// with "true" and leave the merged assume.
1962
1969
if (!CI->use_empty ()) {
1963
- assert (
1964
- all_of (CI->users (), [](User *U) -> bool { return isa<PHINode>(U); }));
1970
+ assert (AlwaysDrop || all_of (CI->users (), [](User *U) -> bool {
1971
+ return isa<PHINode>(U);
1972
+ }));
1965
1973
CI->replaceAllUsesWith (ConstantInt::getTrue (M.getContext ()));
1966
1974
}
1967
1975
CI->eraseFromParent ();
@@ -1974,14 +1982,14 @@ bool LowerTypeTestsModule::lower() {
1974
1982
1975
1983
if (DropTypeTests) {
1976
1984
if (TypeTestFunc)
1977
- dropTypeTests (M, *TypeTestFunc);
1985
+ dropTypeTests (M, *TypeTestFunc, AlwaysDropTests );
1978
1986
// Normally we'd have already removed all @llvm.public.type.test calls,
1979
1987
// except for in the case where we originally were performing ThinLTO but
1980
1988
// decided not to in the backend.
1981
1989
Function *PublicTypeTestFunc =
1982
1990
M.getFunction (Intrinsic::getName (Intrinsic::public_type_test));
1983
1991
if (PublicTypeTestFunc)
1984
- dropTypeTests (M, *PublicTypeTestFunc);
1992
+ dropTypeTests (M, *PublicTypeTestFunc, AlwaysDropTests );
1985
1993
if (TypeTestFunc || PublicTypeTestFunc) {
1986
1994
// We have deleted the type intrinsics, so we no longer have enough
1987
1995
// information to reason about the liveness of virtual function pointers
@@ -2449,9 +2457,9 @@ PreservedAnalyses LowerTypeTestsPass::run(Module &M,
2449
2457
if (UseCommandLine)
2450
2458
Changed = LowerTypeTestsModule::runForTesting (M, AM);
2451
2459
else
2452
- Changed =
2453
- LowerTypeTestsModule (M, AM, ExportSummary, ImportSummary, DropTypeTests)
2454
- .lower ();
2460
+ Changed = LowerTypeTestsModule (M, AM, ExportSummary, ImportSummary,
2461
+ DropTypeTests, AlwaysDropTests )
2462
+ .lower ();
2455
2463
if (!Changed)
2456
2464
return PreservedAnalyses::all ();
2457
2465
return PreservedAnalyses::none ();
0 commit comments