@@ -707,6 +707,8 @@ void SwiftPassInvocation::eraseInstruction(SILInstruction *inst) {
707
707
}
708
708
}
709
709
710
+ // cond_fail removal based on cond_fail message and containing function name.
711
+ //
710
712
// The standard library uses _precondition calls which have a message argument.
711
713
//
712
714
// Allow disabling the generated cond_fail by these message arguments.
@@ -728,6 +730,10 @@ void SwiftPassInvocation::eraseInstruction(SILInstruction *inst) {
728
730
//
729
731
// The optimizer will remove these cond_fails if the swift frontend is invoked
730
732
// with -Xllvm -cond-fail-config-file=/path/to/disable_cond_fails.
733
+ //
734
+ // Additionally, also interpret the lines as function names and check whether
735
+ // the current cond_fail is contained in a listed function when considering
736
+ // whether to remove it.
731
737
static llvm::cl::opt<std::string> CondFailConfigFile (
732
738
" cond-fail-config-file" , llvm::cl::init(" " ),
733
739
llvm::cl::desc(" read the cond_fail message strings to elimimate from file" ));
@@ -750,6 +756,13 @@ bool SILCombiner::shouldRemoveCondFail(CondFailInst &CFI) {
750
756
}
751
757
fs.close ();
752
758
}
759
+ // Check whether the cond_fail's containing function was listed in the config
760
+ // file.
761
+ if (CondFailsToRemove.find (CFI.getFunction ()->getName ().str ()) !=
762
+ CondFailsToRemove.end ())
763
+ return true ;
764
+
765
+ // Check whether the cond_fail's message was listed in the config file.
753
766
auto message = CFI.getMessage ();
754
767
return CondFailsToRemove.find (message.str ()) != CondFailsToRemove.end ();
755
768
}
0 commit comments