@@ -118,10 +118,16 @@ static cl::opt<std::string> ClWriteSummary(
118118 cl::desc (" Write summary to given YAML file after running pass" ),
119119 cl::Hidden);
120120
121- static cl::opt<bool >
121+ static cl::opt<DropTestKind >
122122 ClDropTypeTests (" lowertypetests-drop-type-tests" ,
123- cl::desc (" Simply drop type test assume sequences" ),
124- cl::Hidden, cl::init(false ));
123+ cl::desc (" Simply drop type test sequences" ),
124+ cl::values(clEnumValN(DropTestKind::None, " none" ,
125+ " Do not drop any type tests" ),
126+ clEnumValN(DropTestKind::Assume, " assume" ,
127+ " Drop type test assume sequences" ),
128+ clEnumValN(DropTestKind::All, " all" ,
129+ " Drop all type test sequences" )),
130+ cl::Hidden, cl::init(DropTestKind::None));
125131
126132bool BitSetInfo::containsGlobalOffset (uint64_t Offset) const {
127133 if (Offset < ByteOffset)
@@ -399,7 +405,7 @@ class LowerTypeTestsModule {
399405 const ModuleSummaryIndex *ImportSummary;
400406 // Set when the client has invoked this to simply drop all type test assume
401407 // sequences.
402- bool DropTypeTests;
408+ DropTestKind DropTypeTests;
403409
404410 Triple::ArchType Arch;
405411 Triple::OSType OS;
@@ -542,7 +548,7 @@ class LowerTypeTestsModule {
542548 LowerTypeTestsModule (Module &M, ModuleAnalysisManager &AM,
543549 ModuleSummaryIndex *ExportSummary,
544550 const ModuleSummaryIndex *ImportSummary,
545- bool DropTypeTests);
551+ DropTestKind DropTypeTests);
546552
547553 bool lower ();
548554
@@ -1828,9 +1834,10 @@ void LowerTypeTestsModule::buildBitSetsFromDisjointSet(
18281834// / Lower all type tests in this module.
18291835LowerTypeTestsModule::LowerTypeTestsModule (
18301836 Module &M, ModuleAnalysisManager &AM, ModuleSummaryIndex *ExportSummary,
1831- const ModuleSummaryIndex *ImportSummary, bool DropTypeTests)
1837+ const ModuleSummaryIndex *ImportSummary, DropTestKind DropTypeTests)
18321838 : M(M), ExportSummary(ExportSummary), ImportSummary(ImportSummary),
1833- DropTypeTests(DropTypeTests || ClDropTypeTests) {
1839+ DropTypeTests(ClDropTypeTests > DropTypeTests ? ClDropTypeTests
1840+ : DropTypeTests) {
18341841 assert (!(ExportSummary && ImportSummary));
18351842 Triple TargetTriple (M.getTargetTriple ());
18361843 Arch = TargetTriple.getArch ();
@@ -1882,7 +1889,7 @@ bool LowerTypeTestsModule::runForTesting(Module &M, ModuleAnalysisManager &AM) {
18821889 M, AM,
18831890 ClSummaryAction == PassSummaryAction::Export ? &Summary : nullptr ,
18841891 ClSummaryAction == PassSummaryAction::Import ? &Summary : nullptr ,
1885- /* DropTypeTests*/ false )
1892+ /* DropTypeTests= */ DropTestKind::None )
18861893 .lower ();
18871894
18881895 if (!ClWriteSummary.empty ()) {
@@ -1949,7 +1956,8 @@ void LowerTypeTestsModule::replaceDirectCalls(Value *Old, Value *New) {
19491956 Old->replaceUsesWithIf (New, isDirectCall);
19501957}
19511958
1952- static void dropTypeTests (Module &M, Function &TypeTestFunc) {
1959+ static void dropTypeTests (Module &M, Function &TypeTestFunc,
1960+ bool ShouldDropAll) {
19531961 for (Use &U : llvm::make_early_inc_range (TypeTestFunc.uses ())) {
19541962 auto *CI = cast<CallInst>(U.getUser ());
19551963 // Find and erase llvm.assume intrinsics for this llvm.type.test call.
@@ -1959,9 +1967,13 @@ static void dropTypeTests(Module &M, Function &TypeTestFunc) {
19591967 // If the assume was merged with another assume, we might have a use on a
19601968 // phi (which will feed the assume). Simply replace the use on the phi
19611969 // with "true" and leave the merged assume.
1970+ //
1971+ // If ShouldDropAll is set, then we we need to update any remaining uses,
1972+ // regardless of the instruction type.
19621973 if (!CI->use_empty ()) {
1963- assert (
1964- all_of (CI->users (), [](User *U) -> bool { return isa<PHINode>(U); }));
1974+ assert (ShouldDropAll || all_of (CI->users (), [](User *U) -> bool {
1975+ return isa<PHINode>(U);
1976+ }));
19651977 CI->replaceAllUsesWith (ConstantInt::getTrue (M.getContext ()));
19661978 }
19671979 CI->eraseFromParent ();
@@ -1972,16 +1984,17 @@ bool LowerTypeTestsModule::lower() {
19721984 Function *TypeTestFunc =
19731985 Intrinsic::getDeclarationIfExists (&M, Intrinsic::type_test);
19741986
1975- if (DropTypeTests) {
1987+ if (DropTypeTests != DropTestKind::None) {
1988+ bool ShouldDropAll = DropTypeTests == DropTestKind::All;
19761989 if (TypeTestFunc)
1977- dropTypeTests (M, *TypeTestFunc);
1990+ dropTypeTests (M, *TypeTestFunc, ShouldDropAll );
19781991 // Normally we'd have already removed all @llvm.public.type.test calls,
19791992 // except for in the case where we originally were performing ThinLTO but
19801993 // decided not to in the backend.
19811994 Function *PublicTypeTestFunc =
19821995 Intrinsic::getDeclarationIfExists (&M, Intrinsic::public_type_test);
19831996 if (PublicTypeTestFunc)
1984- dropTypeTests (M, *PublicTypeTestFunc);
1997+ dropTypeTests (M, *PublicTypeTestFunc, ShouldDropAll );
19851998 if (TypeTestFunc || PublicTypeTestFunc) {
19861999 // We have deleted the type intrinsics, so we no longer have enough
19872000 // information to reason about the liveness of virtual function pointers
0 commit comments