Allow user defined error functions
The user can provide function names with
-polly-error-functions=name1,name2,name3
that will be treated as error functions. Any call to them is assumed
not to be executed.
This feature is mainly for developers to play around with the new
"error block" feature.
llvm-svn: 249098
diff --git a/polly/lib/Support/ScopHelper.cpp b/polly/lib/Support/ScopHelper.cpp
index 9acfed6..89c4fa3 100644
--- a/polly/lib/Support/ScopHelper.cpp
+++ b/polly/lib/Support/ScopHelper.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "polly/Support/ScopHelper.h"
+#include "polly/Options.h"
#include "polly/ScopInfo.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -28,6 +29,11 @@
#define DEBUG_TYPE "polly-scop-helper"
+static cl::list<std::string>
+ ErrorFunctions("polly-error-functions",
+ cl::desc("A list of error functions"), cl::Hidden,
+ cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory));
+
Value *polly::getPointerOperand(Instruction &Inst) {
if (LoadInst *load = dyn_cast<LoadInst>(&Inst))
return load->getPointerOperand();
@@ -343,15 +349,21 @@
bool polly::isErrorBlock(BasicBlock &BB) {
- for (Instruction &Inst : BB)
- if (CallInst *CI = dyn_cast<CallInst>(&Inst))
- if (Function *F = CI->getCalledFunction())
- if (F->getName().equals("__ubsan_handle_out_of_bounds"))
- return true;
-
if (isa<UnreachableInst>(BB.getTerminator()))
return true;
+ if (ErrorFunctions.empty())
+ return false;
+
+ for (Instruction &Inst : BB)
+ if (CallInst *CI = dyn_cast<CallInst>(&Inst))
+ if (Function *F = CI->getCalledFunction()) {
+ const auto &FnName = F->getName();
+ for (const auto &ErrorFn : ErrorFunctions)
+ if (FnName.equals(ErrorFn))
+ return true;
+ }
+
return false;
}