@@ -118,10 +118,16 @@ static cl::opt<std::string> ClWriteSummary(
118
118
cl::desc (" Write summary to given YAML file after running pass" ),
119
119
cl::Hidden);
120
120
121
- static cl::opt<bool >
121
+ static cl::opt<DropTestKind >
122
122
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));
125
131
126
132
bool BitSetInfo::containsGlobalOffset (uint64_t Offset) const {
127
133
if (Offset < ByteOffset )
@@ -399,7 +405,7 @@ class LowerTypeTestsModule {
399
405
const ModuleSummaryIndex *ImportSummary;
400
406
// Set when the client has invoked this to simply drop all type test assume
401
407
// sequences.
402
- bool DropTypeTests;
408
+ DropTestKind DropTypeTests;
403
409
404
410
Triple::ArchType Arch;
405
411
Triple::OSType OS;
@@ -542,7 +548,7 @@ class LowerTypeTestsModule {
542
548
LowerTypeTestsModule (Module &M, ModuleAnalysisManager &AM,
543
549
ModuleSummaryIndex *ExportSummary,
544
550
const ModuleSummaryIndex *ImportSummary,
545
- bool DropTypeTests);
551
+ DropTestKind DropTypeTests);
546
552
547
553
bool lower ();
548
554
@@ -1828,9 +1834,10 @@ void LowerTypeTestsModule::buildBitSetsFromDisjointSet(
1828
1834
// / Lower all type tests in this module.
1829
1835
LowerTypeTestsModule::LowerTypeTestsModule (
1830
1836
Module &M, ModuleAnalysisManager &AM, ModuleSummaryIndex *ExportSummary,
1831
- const ModuleSummaryIndex *ImportSummary, bool DropTypeTests)
1837
+ const ModuleSummaryIndex *ImportSummary, DropTestKind DropTypeTests)
1832
1838
: M(M), ExportSummary(ExportSummary), ImportSummary(ImportSummary),
1833
- DropTypeTests(DropTypeTests || ClDropTypeTests) {
1839
+ DropTypeTests(ClDropTypeTests > DropTypeTests ? ClDropTypeTests
1840
+ : DropTypeTests) {
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= */ DropTestKind::None )
1886
1893
.lower ();
1887
1894
1888
1895
if (!ClWriteSummary.empty ()) {
@@ -1949,7 +1956,8 @@ 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,
1960
+ bool ShouldDropAll) {
1953
1961
for (Use &U : llvm::make_early_inc_range (TypeTestFunc.uses ())) {
1954
1962
auto *CI = cast<CallInst>(U.getUser ());
1955
1963
// Find and erase llvm.assume intrinsics for this llvm.type.test call.
@@ -1959,9 +1967,13 @@ static void dropTypeTests(Module &M, Function &TypeTestFunc) {
1959
1967
// If the assume was merged with another assume, we might have a use on a
1960
1968
// phi (which will feed the assume). Simply replace the use on the phi
1961
1969
// 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.
1962
1973
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
+ }));
1965
1977
CI->replaceAllUsesWith (ConstantInt::getTrue (M.getContext ()));
1966
1978
}
1967
1979
CI->eraseFromParent ();
@@ -1972,16 +1984,17 @@ bool LowerTypeTestsModule::lower() {
1972
1984
Function *TypeTestFunc =
1973
1985
Intrinsic::getDeclarationIfExists (&M, Intrinsic::type_test);
1974
1986
1975
- if (DropTypeTests) {
1987
+ if (DropTypeTests != DropTestKind::None) {
1988
+ bool ShouldDropAll = DropTypeTests == DropTestKind::All;
1976
1989
if (TypeTestFunc)
1977
- dropTypeTests (M, *TypeTestFunc);
1990
+ dropTypeTests (M, *TypeTestFunc, ShouldDropAll );
1978
1991
// Normally we'd have already removed all @llvm.public.type.test calls,
1979
1992
// except for in the case where we originally were performing ThinLTO but
1980
1993
// decided not to in the backend.
1981
1994
Function *PublicTypeTestFunc =
1982
1995
Intrinsic::getDeclarationIfExists (&M, Intrinsic::public_type_test);
1983
1996
if (PublicTypeTestFunc)
1984
- dropTypeTests (M, *PublicTypeTestFunc);
1997
+ dropTypeTests (M, *PublicTypeTestFunc, ShouldDropAll );
1985
1998
if (TypeTestFunc || PublicTypeTestFunc) {
1986
1999
// We have deleted the type intrinsics, so we no longer have enough
1987
2000
// information to reason about the liveness of virtual function pointers
0 commit comments