Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/SILOptimizer/SILCombiner/SILCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include <fstream>
#include <set>

using namespace swift;

Expand Down Expand Up @@ -690,3 +693,29 @@ void SwiftPassInvocation::eraseInstruction(SILInstruction *inst) {
}
}
}

static llvm::cl::opt<std::string> CondFailConfigFile(
"cond-fail-config-file", llvm::cl::init(""),
llvm::cl::desc("read the cond_fail message strings to elimimate from file"));

static std::set<std::string> CondFailsToRemove;

bool SILCombiner::shouldRemoveCondFail(CondFailInst &CFI) {
if (CondFailConfigFile.empty())
return false;

std::fstream fs(CondFailConfigFile);
if (!fs) {
llvm::errs() << "cannot cond_fail disablement config file\n";
exit(1);
}
if (CondFailsToRemove.empty()) {
std::string line;
while (std::getline(fs, line)) {
CondFailsToRemove.insert(line);
}
fs.close();
}
auto message = CFI.getMessage();
return CondFailsToRemove.find(message.str()) != CondFailsToRemove.end();
}
2 changes: 2 additions & 0 deletions lib/SILOptimizer/SILCombiner/SILCombiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class SILCombiner :

bool runOnFunction(SILFunction &F);

bool shouldRemoveCondFail(CondFailInst &);

void clear() {
Iteration = 0;
Worklist.resetChecked();
Expand Down
3 changes: 3 additions & 0 deletions lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ SILInstruction *SILCombiner::visitCondFailInst(CondFailInst *CFI) {
if (RemoveCondFails)
return eraseInstFromFunction(*CFI);

if (shouldRemoveCondFail(*CFI))
return eraseInstFromFunction(*CFI);

auto *I = dyn_cast<IntegerLiteralInst>(CFI->getOperand());
if (!I)
return nullptr;
Expand Down