summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mlir/g3doc/WritingAPass.md2
-rw-r--r--mlir/include/mlir/Pass/Pass.h11
-rw-r--r--mlir/include/mlir/Pass/PassManager.h6
-rw-r--r--mlir/lib/ExecutionEngine/ExecutionEngine.cpp2
-rw-r--r--mlir/lib/Pass/Pass.cpp50
-rw-r--r--mlir/tools/mlir-opt/mlir-opt.cpp2
6 files changed, 35 insertions, 38 deletions
diff --git a/mlir/g3doc/WritingAPass.md b/mlir/g3doc/WritingAPass.md
index ddcf03c2fa7..a111937ed9e 100644
--- a/mlir/g3doc/WritingAPass.md
+++ b/mlir/g3doc/WritingAPass.md
@@ -246,7 +246,7 @@ pm.addPass(new MyModulePass2());
// Run the pass manager on a module.
Module *m = ...;
-if (!pm.run(m))
+if (failed(pm.run(m)))
... // One of the passes signaled a failure.
```
diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h
index 356b6a95b4f..dcbdd48671a 100644
--- a/mlir/include/mlir/Pass/Pass.h
+++ b/mlir/include/mlir/Pass/Pass.h
@@ -20,6 +20,7 @@
#include "mlir/Pass/AnalysisManager.h"
#include "mlir/Pass/PassRegistry.h"
+#include "mlir/Support/Status.h"
#include "llvm/ADT/PointerIntPair.h"
namespace mlir {
@@ -116,10 +117,9 @@ protected:
}
private:
- /// Forwarding function to execute this pass. Returns false if the pass
- /// execution failed, true otherwise.
+ /// Forwarding function to execute this pass.
LLVM_NODISCARD
- bool run(Function *fn, FunctionAnalysisManager &fam);
+ Status run(Function *fn, FunctionAnalysisManager &fam);
/// The current execution state for the pass.
llvm::Optional<PassStateT> passState;
@@ -159,10 +159,9 @@ protected:
}
private:
- /// Forwarding function to execute this pass. Returns false if the pass
- /// execution failed, true otherwise.
+ /// Forwarding function to execute this pass.
LLVM_NODISCARD
- bool run(Module *module, ModuleAnalysisManager &mam);
+ Status run(Module *module, ModuleAnalysisManager &mam);
/// The current execution state for the pass.
llvm::Optional<PassStateT> passState;
diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h
index a774a354276..e69514ddf86 100644
--- a/mlir/include/mlir/Pass/PassManager.h
+++ b/mlir/include/mlir/Pass/PassManager.h
@@ -18,6 +18,7 @@
#ifndef MLIR_PASS_PASSMANAGER_H
#define MLIR_PASS_PASSMANAGER_H
+#include "mlir/Support/Status.h"
#include "llvm/ADT/SmallVector.h"
namespace mlir {
@@ -51,10 +52,9 @@ public:
/// executor if necessary.
void addPass(FunctionPassBase *pass);
- /// Run the passes within this manager on the provided module. Returns false
- /// if the run failed, true otherwise.
+ /// Run the passes within this manager on the provided module.
LLVM_NODISCARD
- bool run(Module *module);
+ Status run(Module *module);
private:
/// A stack of nested pass executors on sub-module IR units, e.g. function.
diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index d47c0832771..9c407528c0d 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -284,7 +284,7 @@ Expected<std::unique_ptr<ExecutionEngine>> ExecutionEngine::create(
// Construct and run the default MLIR pipeline.
PassManager manager;
getDefaultPasses(manager, {});
- if (!manager.run(m))
+ if (failed(manager.run(m)))
return make_string_error("passes failed");
auto llvmModule = translateModuleToLLVMIR(*m);
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 59dadb12e56..77e8be5cea2 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -34,9 +34,8 @@ using namespace mlir::detail;
/// single .o file.
void Pass::anchor() {}
-/// Forwarding function to execute this pass. Returns false if the pass
-/// execution failed, true otherwise.
-bool FunctionPassBase::run(Function *fn, FunctionAnalysisManager &fam) {
+/// Forwarding function to execute this pass.
+Status FunctionPassBase::run(Function *fn, FunctionAnalysisManager &fam) {
// Initialize the pass state.
passState.emplace(fn, fam);
@@ -47,12 +46,12 @@ bool FunctionPassBase::run(Function *fn, FunctionAnalysisManager &fam) {
fam.invalidate(passState->preservedAnalyses);
// Return false if the pass signaled a failure.
- return !passState->irAndPassFailed.getInt();
+ return passState->irAndPassFailed.getInt() ? Status::failure()
+ : Status::success();
}
-/// Forwarding function to execute this pass. Returns false if the pass
-/// execution failed, true otherwise.
-bool ModulePassBase::run(Module *module, ModuleAnalysisManager &mam) {
+/// Forwarding function to execute this pass.
+Status ModulePassBase::run(Module *module, ModuleAnalysisManager &mam) {
// Initialize the pass state.
passState.emplace(module, mam);
@@ -63,7 +62,8 @@ bool ModulePassBase::run(Module *module, ModuleAnalysisManager &mam) {
mam.invalidate(passState->preservedAnalyses);
// Return false if the pass signaled a failure.
- return !passState->irAndPassFailed.getInt();
+ return passState->irAndPassFailed.getInt() ? Status::failure()
+ : Status::success();
}
//===----------------------------------------------------------------------===//
@@ -96,9 +96,8 @@ public:
FunctionPassExecutor(const FunctionPassExecutor &) = delete;
FunctionPassExecutor &operator=(const FunctionPassExecutor &) = delete;
- /// Run the executor on the given function. Returns false if the pass
- /// execution failed, true otherwise.
- bool run(Function *function, FunctionAnalysisManager &fam);
+ /// Run the executor on the given function.
+ Status run(Function *function, FunctionAnalysisManager &fam);
/// Add a pass to the current executor. This takes ownership over the provided
/// pass pointer.
@@ -122,9 +121,8 @@ public:
ModulePassExecutor(const ModulePassExecutor &) = delete;
ModulePassExecutor &operator=(const ModulePassExecutor &) = delete;
- /// Run the executor on the given module. Returns false if the pass
- /// execution failed, true otherwise.
- bool run(Module *module, ModuleAnalysisManager &mam);
+ /// Run the executor on the given module.
+ Status run(Module *module, ModuleAnalysisManager &mam);
/// Add a pass to the current executor. This takes ownership over the provided
/// pass pointer.
@@ -142,23 +140,23 @@ private:
} // end namespace mlir
/// Run all of the passes in this manager over the current function.
-bool detail::FunctionPassExecutor::run(Function *function,
- FunctionAnalysisManager &fam) {
+Status detail::FunctionPassExecutor::run(Function *function,
+ FunctionAnalysisManager &fam) {
// Run each of the held passes.
for (auto &pass : passes)
- if (!pass->run(function, fam))
- return false;
- return true;
+ if (failed(pass->run(function, fam)))
+ return Status::failure();
+ return Status::success();
}
/// Run all of the passes in this manager over the current module.
-bool detail::ModulePassExecutor::run(Module *module,
- ModuleAnalysisManager &mam) {
+Status detail::ModulePassExecutor::run(Module *module,
+ ModuleAnalysisManager &mam) {
// Run each of the held passes.
for (auto &pass : passes)
- if (!pass->run(module, mam))
- return false;
- return true;
+ if (failed(pass->run(module, mam)))
+ return Status::failure();
+ return Status::success();
}
//===----------------------------------------------------------------------===//
@@ -202,7 +200,7 @@ void ModuleToFunctionPassAdaptor::runOnModule() {
// Run the held function pipeline over the current function.
auto fam = mam.slice(&func);
- if (!fpe.run(&func, fam))
+ if (failed(fpe.run(&func, fam)))
return signalPassFailure();
// Clear out any computed function analyses. These analyses won't be used
@@ -290,7 +288,7 @@ void PassManager::addPass(FunctionPassBase *pass) {
}
/// Run the passes within this manager on the provided module.
-bool PassManager::run(Module *module) {
+Status PassManager::run(Module *module) {
ModuleAnalysisManager mam(module);
return mpe->run(module, mam);
}
diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index f6db80541b3..47ee37238bc 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -134,7 +134,7 @@ static OptResult performActions(SourceMgr &sourceMgr, MLIRContext *context) {
PassManager pm(verifyPasses);
for (const auto *passEntry : *passList)
passEntry->addToPipeline(pm);
- if (!pm.run(module.get()))
+ if (failed(pm.run(module.get())))
return OptFailure;
std::string errorMessage;
OpenPOWER on IntegriCloud