File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
lib/SILOptimizer/SILCombiner Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 4343#include " llvm/ADT/SmallPtrSet.h"
4444#include " llvm/ADT/SmallVector.h"
4545#include " llvm/ADT/Statistic.h"
46+ #include " llvm/Support/CommandLine.h"
4647#include " llvm/Support/Debug.h"
48+ #include < fstream>
49+ #include < set>
4750
4851using namespace swift ;
4952
@@ -703,3 +706,29 @@ void SwiftPassInvocation::eraseInstruction(SILInstruction *inst) {
703706 }
704707 }
705708}
709+
710+ static llvm::cl::opt<std::string> CondFailConfigFile (
711+ " cond-fail-config-file" , llvm::cl::init(" " ),
712+ llvm::cl::desc(" read the cond_fail message strings to elimimate from file" ));
713+
714+ static std::set<std::string> CondFailsToRemove;
715+
716+ bool SILCombiner::shouldRemoveCondFail (CondFailInst &CFI) {
717+ if (CondFailConfigFile.empty ())
718+ return false ;
719+
720+ std::fstream fs (CondFailConfigFile);
721+ if (!fs) {
722+ llvm::errs () << " cannot cond_fail disablement config file\n " ;
723+ exit (1 );
724+ }
725+ if (CondFailsToRemove.empty ()) {
726+ std::string line;
727+ while (std::getline (fs, line)) {
728+ CondFailsToRemove.insert (line);
729+ }
730+ fs.close ();
731+ }
732+ auto message = CFI.getMessage ();
733+ return CondFailsToRemove.find (message.str ()) != CondFailsToRemove.end ();
734+ }
Original file line number Diff line number Diff line change @@ -136,6 +136,8 @@ class SILCombiner :
136136
137137 bool runOnFunction (SILFunction &F);
138138
139+ bool shouldRemoveCondFail (CondFailInst &);
140+
139141 void clear () {
140142 Iteration = 0 ;
141143 Worklist.resetChecked ();
Original file line number Diff line number Diff line change @@ -537,6 +537,9 @@ SILInstruction *SILCombiner::visitCondFailInst(CondFailInst *CFI) {
537537 if (RemoveCondFails)
538538 return eraseInstFromFunction (*CFI);
539539
540+ if (shouldRemoveCondFail (*CFI))
541+ return eraseInstFromFunction (*CFI);
542+
540543 auto *I = dyn_cast<IntegerLiteralInst>(CFI->getOperand ());
541544 if (!I)
542545 return nullptr ;
You can’t perform that action at this time.
0 commit comments