Remove PassResult and have the runOnFunction/runOnModule functions return void instea...
authorRiver Riddle <riverriddle@google.com>
Thu, 28 Feb 2019 22:50:42 +0000 (14:50 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 23:50:44 +0000 (16:50 -0700)
PiperOrigin-RevId: 236202029

28 files changed:
mlir/include/mlir/Pass/Pass.h
mlir/include/mlir/Pass/PassManager.h
mlir/lib/Analysis/MemRefBoundCheck.cpp
mlir/lib/Analysis/MemRefDependenceCheck.cpp
mlir/lib/Analysis/OpStats.cpp
mlir/lib/EDSC/LowerEDSCTestPass.cpp
mlir/lib/ExecutionEngine/ExecutionEngine.cpp
mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
mlir/lib/Pass/Pass.cpp
mlir/lib/Transforms/CSE.cpp
mlir/lib/Transforms/Canonicalizer.cpp
mlir/lib/Transforms/ConstantFold.cpp
mlir/lib/Transforms/DmaGeneration.cpp
mlir/lib/Transforms/LoopFusion.cpp
mlir/lib/Transforms/LoopTiling.cpp
mlir/lib/Transforms/LoopUnroll.cpp
mlir/lib/Transforms/LoopUnrollAndJam.cpp
mlir/lib/Transforms/LowerAffine.cpp
mlir/lib/Transforms/LowerVectorTransfers.cpp
mlir/lib/Transforms/MaterializeVectors.cpp
mlir/lib/Transforms/MemRefDataFlowOpt.cpp
mlir/lib/Transforms/PipelineDataTransfer.cpp
mlir/lib/Transforms/SimplifyAffineStructures.cpp
mlir/lib/Transforms/StripDebugInfo.cpp
mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp
mlir/lib/Transforms/Vectorize.cpp
mlir/lib/Transforms/ViewFunctionGraph.cpp
mlir/tools/mlir-opt/mlir-opt.cpp

index 26b76e317eb9e575a77d55f049053998dab55ccd..6a1e2791ed476638853eda72341bf25da37af5f1 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef MLIR_PASS_PASS_H
 #define MLIR_PASS_PASS_H
 
+#include "mlir/IR/Module.h"
 #include "mlir/Pass/PassRegistry.h"
 #include "llvm/ADT/PointerIntPair.h"
 
@@ -25,15 +26,6 @@ namespace mlir {
 class Function;
 class Module;
 
-// Values that can be used by to signal success/failure. This can be implicitly
-// converted to/from boolean values, with false representing success and true
-// failure.
-struct LLVM_NODISCARD PassResult {
-  enum ResultEnum { Success, Failure } value;
-  PassResult(ResultEnum v) : value(v) {}
-  operator bool() const { return value == Failure; }
-};
-
 /// The abstract base pass class. This class contains information describing the
 /// derived pass object, e.g its kind and abstract PassInfo.
 class Pass {
@@ -45,9 +37,6 @@ public:
   /// Returns the unique identifier that corresponds to this pass.
   const PassID *getPassID() const { return passIDAndKind.getPointer(); }
 
-  static PassResult success() { return PassResult::Success; }
-  static PassResult failure() { return PassResult::Failure; }
-
   /// Returns the pass info for the specified pass class or null if unknown.
   static const PassInfo *lookupPassInfo(const PassID *passID);
   template <typename PassT> static const PassInfo *lookupPassInfo() {
@@ -79,10 +68,10 @@ class ModulePassExecutor;
 /// The state for a single execution of a pass. This provides a unified
 /// interface for accessing and initializing necessary state for pass execution.
 template <typename IRUnitT> struct PassExecutionState {
-  explicit PassExecutionState(IRUnitT *ir) : ir(ir) {}
+  explicit PassExecutionState(IRUnitT *ir) : irAndPassFailed(ir, false) {}
 
   /// The current IR unit being transformed.
-  IRUnitT *ir;
+  llvm::PointerIntPair<IRUnitT *, 1, bool> irAndPassFailed;
 };
 } // namespace detail
 
@@ -99,17 +88,24 @@ protected:
   explicit FunctionPassBase(const PassID *id) : Pass(id, Kind::FunctionPass) {}
 
   /// The polymorphic API that runs the pass over the currently held function.
-  virtual PassResult runOnFunction() = 0;
+  virtual void runOnFunction() = 0;
 
   /// Return the current function being transformed.
   Function &getFunction() {
+    return *getPassState().irAndPassFailed.getPointer();
+  }
+
+  /// Returns the current pass state.
+  detail::PassExecutionState<Function> &getPassState() {
     assert(passState && "pass state was never initialized");
-    return *passState->ir;
+    return *passState;
   }
 
 private:
-  /// Forwarding function to execute this pass.
-  PassResult run(Function *fn);
+  /// Forwarding function to execute this pass. Returns false if the pass
+  /// execution failed, true otherwise.
+  LLVM_NODISCARD
+  bool run(Function *fn);
 
   /// The current execution state for the pass.
   llvm::Optional<detail::PassExecutionState<Function>> passState;
@@ -130,17 +126,22 @@ protected:
   explicit ModulePassBase(const PassID *id) : Pass(id, Kind::ModulePass) {}
 
   /// The polymorphic API that runs the pass over the currently held module.
-  virtual PassResult runOnModule() = 0;
+  virtual void runOnModule() = 0;
 
   /// Return the current module being transformed.
-  Module &getModule() {
+  Module &getModule() { return *getPassState().irAndPassFailed.getPointer(); }
+
+  /// Returns the current pass state.
+  detail::PassExecutionState<Module> &getPassState() {
     assert(passState && "pass state was never initialized");
-    return *passState->ir;
+    return *passState;
   }
 
 private:
-  /// Forwarding function to execute this pass.
-  PassResult run(Module *module);
+  /// Forwarding function to execute this pass. Returns false if the pass
+  /// execution failed, true otherwise.
+  LLVM_NODISCARD
+  bool run(Module *module);
 
   /// The current execution state for the pass.
   llvm::Optional<detail::PassExecutionState<Module>> passState;
@@ -162,6 +163,12 @@ protected:
 
   /// TODO(riverriddle) Provide additional utilities for cloning, getting the
   /// derived class name, etc..
+
+  /// Signal that some invariant was broken when running. The IR is allowed to
+  /// be in an invalid state.
+  void signalPassFailure() {
+    this->getPassState().irAndPassFailed.setInt(true);
+  }
 };
 } // end namespace detail
 
@@ -174,14 +181,14 @@ protected:
 ///     additional functions.
 ///
 /// Derived function passes are expected to provide the following:
-///   - A 'PassResult runOnFunction()' method.
+///   - A 'void runOnFunction()' method.
 template <typename T>
 using FunctionPass = detail::PassModel<Function, T, FunctionPassBase>;
 
 /// A model for providing module pass specific utilities.
 ///
 /// Derived module passes are expected to provide the following:
-///   - A 'PassResult runOnModule()' method.
+///   - A 'void runOnModule()' method.
 template <typename T>
 using ModulePass = detail::PassModel<Module, T, ModulePassBase>;
 } // end namespace mlir
index 981d860888d5f04949292d9dac702ccbb64e1bde..2c00e3dd90203e951cc4c5a2686f0a71be7b4918 100644 (file)
@@ -50,7 +50,9 @@ public:
   /// executor if necessary.
   void addPass(FunctionPassBase *pass);
 
-  /// Run the passes within this manager on the provided module.
+  /// Run the passes within this manager on the provided module. Returns false
+  /// if the run failed, true otherwise.
+  LLVM_NODISCARD
   bool run(Module *module);
 
 private:
index a6730f0119913b9db1434b6823a80ab0e4360a06..d709566c32268f4f41e0ffe685b7900495956df8 100644 (file)
@@ -38,7 +38,7 @@ namespace {
 
 /// Checks for out of bound memef access subscripts..
 struct MemRefBoundCheck : public FunctionPass<MemRefBoundCheck> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 
 } // end anonymous namespace
@@ -47,7 +47,7 @@ FunctionPassBase *mlir::createMemRefBoundCheckPass() {
   return new MemRefBoundCheck();
 }
 
-PassResult MemRefBoundCheck::runOnFunction() {
+void MemRefBoundCheck::runOnFunction() {
   getFunction().walk([](Instruction *opInst) {
     if (auto loadOp = opInst->dyn_cast<LoadOp>()) {
       boundCheckLoadOrStoreOp(loadOp);
@@ -56,7 +56,6 @@ PassResult MemRefBoundCheck::runOnFunction() {
     }
     // TODO(bondhugula): do this for DMA ops as well.
   });
-  return success();
 }
 
 static PassRegistration<MemRefBoundCheck>
index 33488f0c7a821254ed6b80d08276bc1a3eb28cc5..d0074dad7f26780fe925e2a23ab6d2ada7e4bfcb 100644 (file)
@@ -39,7 +39,7 @@ namespace {
 /// Checks dependences between all pairs of memref accesses in a Function.
 struct MemRefDependenceCheck : public FunctionPass<MemRefDependenceCheck> {
   SmallVector<Instruction *, 4> loadsAndStores;
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 
 } // end anonymous namespace
@@ -111,7 +111,7 @@ static void checkDependences(ArrayRef<Instruction *> loadsAndStores) {
 
 // Walks the Function 'f' adding load and store ops to 'loadsAndStores'.
 // Runs pair-wise dependence checks.
-PassResult MemRefDependenceCheck::runOnFunction() {
+void MemRefDependenceCheck::runOnFunction() {
   // Collect the loads and stores within the function.
   loadsAndStores.clear();
   getFunction().walk([&](Instruction *inst) {
@@ -120,7 +120,6 @@ PassResult MemRefDependenceCheck::runOnFunction() {
   });
 
   checkDependences(loadsAndStores);
-  return success();
 }
 
 static PassRegistration<MemRefDependenceCheck>
index a17be9d176be46b7320686987938538c0ddb511a..3fdbc9c1d46b3a23c834e851592a0330ff0507a9 100644 (file)
@@ -30,7 +30,7 @@ struct PrintOpStatsPass : public ModulePass<PrintOpStatsPass> {
   explicit PrintOpStatsPass(llvm::raw_ostream &os = llvm::errs()) : os(os) {}
 
   // Prints the resultant operation statistics post iterating over the module.
-  PassResult runOnModule() override;
+  void runOnModule() override;
 
   // Print summary of op stats.
   void printSummary();
@@ -41,7 +41,7 @@ private:
 };
 } // namespace
 
-PassResult PrintOpStatsPass::runOnModule() {
+void PrintOpStatsPass::runOnModule() {
   opCount.clear();
 
   // Compute the operation statistics for each function in the module.
@@ -49,7 +49,6 @@ PassResult PrintOpStatsPass::runOnModule() {
     fn.walk(
         [&](Instruction *inst) { ++opCount[inst->getName().getStringRef()]; });
   printSummary();
-  return success();
 }
 
 void PrintOpStatsPass::printSummary() {
index 2b6c38bf8c62c9d816ced9ec04e06812f69f2c5f..db30eef17bf42fcd9bd02d69469672d3abadbe42 100644 (file)
@@ -34,13 +34,13 @@ using namespace mlir;
 namespace {
 // Testing pass to lower EDSC.
 struct LowerEDSCTestPass : public FunctionPass<LowerEDSCTestPass> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 } // end anonymous namespace
 
 #include "mlir/EDSC/reference-impl.inc"
 
-PassResult LowerEDSCTestPass::runOnFunction() {
+void LowerEDSCTestPass::runOnFunction() {
   getFunction().walk([](Instruction *op) {
     if (op->getName().getStringRef() == "print") {
       auto opName = op->getAttrOfType<StringAttr>("op");
@@ -56,7 +56,6 @@ PassResult LowerEDSCTestPass::runOnFunction() {
       printRefImplementation(opName.getValue(), function.getValue());
     }
   });
-  return success();
 }
 
 static PassRegistration<LowerEDSCTestPass> pass("lower-edsc-test",
index f0835da77d481034d172c466e28ce358054d8d1e..d47c08327719e666507065dd442fcc2eba7457fa 100644 (file)
@@ -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 (!manager.run(m))
     return make_string_error("passes failed");
 
   auto llvmModule = translateModuleToLLVMIR(*m);
index 1994d4da233d0be5947facc143092f8479c0fccd..3ec934e329a7b466d910d7967b832fe996f61706 100644 (file)
@@ -1097,10 +1097,11 @@ static void ensureDistinctSuccessors(Module *m) {
 /// dialect.
 class LLVMLowering : public ModulePass<LLVMLowering>, public DialectConversion {
 public:
-  PassResult runOnModule() override {
+  void runOnModule() override {
     Module *m = &getModule();
     uniqueSuccessorsWithArguments(m);
-    return DialectConversion::convert(m) ? failure() : success();
+    if (DialectConversion::convert(m))
+      signalPassFailure();
   }
 
 protected:
index 33f3048321f7b99743dfd424b490ab8cd841d1b6..f3ac6def20f8b9e47af0fd5bd5109313e93e4641 100644 (file)
@@ -35,21 +35,28 @@ using namespace mlir::detail;
 void Pass::anchor() {}
 
 /// Forwarding function to execute this pass.
-PassResult FunctionPassBase::run(Function *fn) {
+bool FunctionPassBase::run(Function *fn) {
   /// Initialize the pass state.
   passState.emplace(fn);
 
   /// Invoke the virtual runOnFunction function.
-  return runOnFunction();
+  runOnFunction();
+
+  // Return false if the pass signaled a failure.
+  return !passState->irAndPassFailed.getInt();
 }
 
-/// Forwarding function to execute this pass.
-PassResult ModulePassBase::run(Module *module) {
+/// Forwarding function to execute this pass. Returns false if the pass
+/// execution failed, true otherwise.
+bool ModulePassBase::run(Module *module) {
   /// Initialize the pass state.
   passState.emplace(module);
 
   /// Invoke the virtual runOnModule function.
-  return runOnModule();
+  runOnModule();
+
+  // Return false if the pass signaled a failure.
+  return !passState->irAndPassFailed.getInt();
 }
 
 //===----------------------------------------------------------------------===//
@@ -82,7 +89,9 @@ public:
   FunctionPassExecutor(const FunctionPassExecutor &) = delete;
   FunctionPassExecutor &operator=(const FunctionPassExecutor &) = delete;
 
-  /// Run the executor on the given function.
+  /// Run the executor on the given function. Returns false if the pass
+  /// execution failed, true otherwise.
+  LLVM_NODISCARD
   bool run(Function *function);
 
   /// Add a pass to the current executor. This takes ownership over the provided
@@ -107,7 +116,9 @@ public:
   ModulePassExecutor(const ModulePassExecutor &) = delete;
   ModulePassExecutor &operator=(const ModulePassExecutor &) = delete;
 
-  /// Run the executor on the given module.
+  /// Run the executor on the given module. Returns false if the pass
+  /// execution failed, true otherwise.
+  LLVM_NODISCARD
   bool run(Module *module);
 
   /// Add a pass to the current executor. This takes ownership over the provided
@@ -129,25 +140,25 @@ private:
 bool detail::FunctionPassExecutor::run(Function *function) {
   for (auto &pass : passes) {
     /// Create an execution state for this pass.
-    if (pass->run(function))
-      return true;
+    if (!pass->run(function))
+      return false;
     // TODO: This should be opt-out and handled separately.
     if (function->verify())
-      return true;
+      return false;
   }
-  return false;
+  return true;
 }
 
 /// Run all of the passes in this manager over the current module.
 bool detail::ModulePassExecutor::run(Module *module) {
   for (auto &pass : passes) {
-    if (pass->run(module))
-      return true;
+    if (!pass->run(module))
+      return false;
     // TODO: This should be opt-out and handled separately.
     if (module->verify())
-      return true;
+      return false;
   }
-  return false;
+  return true;
 }
 
 //===----------------------------------------------------------------------===//
@@ -168,9 +179,9 @@ public:
   ModuleToFunctionPassAdaptor &
   operator=(const ModuleToFunctionPassAdaptor &) = delete;
 
-  /// run the held function pipeline over all non-external functions within the
+  /// Run the held function pipeline over all non-external functions within the
   /// module.
-  PassResult runOnModule() override;
+  void runOnModule() override;
 
   /// Returns the function pass executor for this adaptor.
   FunctionPassExecutor &getFunctionExecutor() { return fpe; }
@@ -182,17 +193,16 @@ private:
 
 /// Execute the held function pass over all non-external functions within the
 /// module.
-PassResult ModuleToFunctionPassAdaptor::runOnModule() {
+void ModuleToFunctionPassAdaptor::runOnModule() {
   for (auto &func : getModule()) {
     // Skip external functions.
     if (func.isExternal())
       continue;
 
     // Run the held function pipeline over the current function.
-    if (fpe.run(&func))
-      return failure();
+    if (!fpe.run(&func))
+      return signalPassFailure();
   }
-  return success();
 }
 
 //===----------------------------------------------------------------------===//
index 24b5322061316409e62aa3061e6e2c0fba0c5efb..f4b51c3edd7d886a72bd70aab3ae0458a03f8665 100644 (file)
@@ -111,7 +111,7 @@ struct CSE : public FunctionPass<CSE> {
   void simplifyBlock(DominanceInfo &domInfo, Block *bb);
   void simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList);
 
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 
 private:
   /// A scoped hash table of defining operations within a function.
@@ -216,7 +216,7 @@ void CSE::simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList) {
   }
 }
 
-PassResult CSE::runOnFunction() {
+void CSE::runOnFunction() {
   DominanceInfo domInfo(&getFunction());
   simplifyBlockList(domInfo, getFunction().getBlockList());
 
@@ -224,8 +224,6 @@ PassResult CSE::runOnFunction() {
   for (auto *op : opsToErase)
     op->erase();
   opsToErase.clear();
-
-  return success();
 }
 
 FunctionPassBase *mlir::createCSEPass() { return new CSE(); }
index 764f055a6732d0da31c6b738121b5ee0d313aa34..17259bb19dac2bba955e87edbfb854bee1376265 100644 (file)
@@ -34,11 +34,11 @@ namespace {
 
 /// Canonicalize operations in functions.
 struct Canonicalizer : public FunctionPass<Canonicalizer> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 } // end anonymous namespace
 
-PassResult Canonicalizer::runOnFunction() {
+void Canonicalizer::runOnFunction() {
   OwningRewritePatternList patterns;
   auto &func = getFunction();
 
@@ -50,7 +50,6 @@ PassResult Canonicalizer::runOnFunction() {
     op->getCanonicalizationPatterns(patterns, context);
 
   applyPatternsGreedily(&func, std::move(patterns));
-  return success();
 }
 
 /// Create a Canonicalizer pass.
index ed35c03755fae52ec516979c1c322aa80545cdd2..6274d7dc8570ae97d21cb7586d970e0f97210c6d 100644 (file)
@@ -33,7 +33,7 @@ struct ConstantFold : public FunctionPass<ConstantFold> {
   std::vector<Instruction *> opInstsToErase;
 
   void foldInstruction(Instruction *op);
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 } // end anonymous namespace
 
@@ -92,7 +92,7 @@ void ConstantFold::foldInstruction(Instruction *op) {
 // For now, we do a simple top-down pass over a function folding constants.  We
 // don't handle conditional control flow, block arguments, folding
 // conditional branches, or anything else fancy.
-PassResult ConstantFold::runOnFunction() {
+void ConstantFold::runOnFunction() {
   existingConstants.clear();
   opInstsToErase.clear();
 
@@ -113,8 +113,6 @@ PassResult ConstantFold::runOnFunction() {
     if (cst->use_empty())
       cst->getDefiningInst()->erase();
   }
-
-  return success();
 }
 
 /// Creates a constant folding pass.
index 82ba07acb5f652ca1935355dd36f19652d95fbc4..53bc56173d220c58c529a002fe1853a97f5e95d6 100644 (file)
@@ -84,7 +84,7 @@ struct DmaGeneration : public FunctionPass<DmaGeneration> {
         minDmaTransferSize(minDmaTransferSize),
         fastMemCapacityBytes(fastMemCapacityBytes) {}
 
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
   bool runOnBlock(Block *block);
   uint64_t runOnBlock(Block::iterator begin, Block::iterator end);
 
@@ -754,16 +754,13 @@ uint64_t DmaGeneration::runOnBlock(Block::iterator begin, Block::iterator end) {
   return totalDmaBuffersSizeInBytes;
 }
 
-PassResult DmaGeneration::runOnFunction() {
+void DmaGeneration::runOnFunction() {
   Function *f = &getFunction();
   FuncBuilder topBuilder(f);
   zeroIndex = topBuilder.create<ConstantIndexOp>(f->getLoc(), 0);
 
-  for (auto &block : *f) {
+  for (auto &block : *f)
     runOnBlock(&block);
-  }
-  // This function never leaves the IR in an invalid state.
-  return success();
 }
 
 static PassRegistration<DmaGeneration>
index 1528e394506e60060f088908f1e0b53685eaf7b7..61d13325d136227251e3b3908b85b729829f7d52 100644 (file)
@@ -91,7 +91,7 @@ struct LoopFusion : public FunctionPass<LoopFusion> {
       : localBufSizeThreshold(localBufSizeThreshold),
         fastMemorySpace(fastMemorySpace) {}
 
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 
   // Any local buffers smaller than this size (in bytes) will be created in
   // `fastMemorySpace` if provided.
@@ -1800,7 +1800,7 @@ public:
 
 } // end anonymous namespace
 
-PassResult LoopFusion::runOnFunction() {
+void LoopFusion::runOnFunction() {
   // Override if a command line argument was provided.
   if (clFusionFastMemorySpace.getNumOccurrences() > 0) {
     fastMemorySpace = clFusionFastMemorySpace.getValue();
@@ -1814,7 +1814,6 @@ PassResult LoopFusion::runOnFunction() {
   MemRefDependenceGraph g;
   if (g.init(&getFunction()))
     GreedyFusion(&g).run(localBufSizeThreshold, fastMemorySpace);
-  return success();
 }
 
 static PassRegistration<LoopFusion> pass("loop-fusion", "Fuse loop nests");
index db0e8d51ad85be66eb213fc4aed9c53e1192c1b5..4aebbc2e85657f11bbed38fe45b6ebccdb6938ae 100644 (file)
@@ -48,7 +48,7 @@ namespace {
 
 /// A pass to perform loop tiling on all suitable loop nests of a Function.
 struct LoopTiling : public FunctionPass<LoopTiling> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 
   constexpr static unsigned kDefaultTileSize = 4;
 };
@@ -253,7 +253,7 @@ getTileableBands(Function *f,
         getMaximalPerfectLoopNest(forOp);
 }
 
-PassResult LoopTiling::runOnFunction() {
+void LoopTiling::runOnFunction() {
   std::vector<SmallVector<OpPointer<AffineForOp>, 6>> bands;
   getTileableBands(&getFunction(), &bands);
 
@@ -265,11 +265,9 @@ PassResult LoopTiling::runOnFunction() {
               clTileSizes.begin() + std::min(clTileSizes.size(), band.size()),
               tileSizes.begin());
 
-    if (tileCodeGen(band, tileSizes)) {
-      return failure();
-    }
+    if (tileCodeGen(band, tileSizes))
+      return signalPassFailure();
   }
-  return success();
 }
 
 static PassRegistration<LoopTiling> pass("loop-tile", "Tile loop nests");
index 231dba657200b812927b0eccaa9a3ac2b63c3520..2bf78ae258e49157d82eb01eaa4343c84066e7b6 100644 (file)
@@ -79,7 +79,7 @@ struct LoopUnroll : public FunctionPass<LoopUnroll> {
       : unrollFactor(unrollFactor), unrollFull(unrollFull),
         getUnrollFactor(getUnrollFactor) {}
 
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 
   /// Unroll this for inst. Returns false if nothing was done.
   bool runOnAffineForOp(OpPointer<AffineForOp> forOp);
@@ -88,7 +88,7 @@ struct LoopUnroll : public FunctionPass<LoopUnroll> {
 };
 } // end anonymous namespace
 
-PassResult LoopUnroll::runOnFunction() {
+void LoopUnroll::runOnFunction() {
   // Gathers all innermost loops through a post order pruned walk.
   struct InnermostLoopGatherer {
     // Store innermost loops as we walk.
@@ -137,7 +137,7 @@ PassResult LoopUnroll::runOnFunction() {
     });
     for (auto forOp : loops)
       loopUnrollFull(forOp);
-    return success();
+    return;
   }
 
   unsigned numRepetitions = clUnrollNumRepetitions.getNumOccurrences() > 0
@@ -158,7 +158,6 @@ PassResult LoopUnroll::runOnFunction() {
       // Break out if nothing was unrolled.
       break;
   }
-  return success();
 }
 
 /// Unrolls a 'for' inst. Returns true if the loop was unrolled, false
index e950d117ddcb313101f22c92de96c074f09c82c2..87259497cef40af556c1a2a70181ee4d7a219fd2 100644 (file)
@@ -78,7 +78,7 @@ struct LoopUnrollAndJam : public FunctionPass<LoopUnrollAndJam> {
   explicit LoopUnrollAndJam(Optional<unsigned> unrollJamFactor = None)
       : unrollJamFactor(unrollJamFactor) {}
 
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
   bool runOnAffineForOp(OpPointer<AffineForOp> forOp);
 };
 } // end anonymous namespace
@@ -88,15 +88,13 @@ FunctionPassBase *mlir::createLoopUnrollAndJamPass(int unrollJamFactor) {
       unrollJamFactor == -1 ? None : Optional<unsigned>(unrollJamFactor));
 }
 
-PassResult LoopUnrollAndJam::runOnFunction() {
+void LoopUnrollAndJam::runOnFunction() {
   // Currently, just the outermost loop from the first loop nest is
   // unroll-and-jammed by this pass. However, runOnAffineForOp can be called on
   // any for operation.
   auto &entryBlock = getFunction().front();
   if (auto forOp = entryBlock.front().dyn_cast<AffineForOp>())
     runOnAffineForOp(forOp);
-
-  return success();
 }
 
 /// Unroll and jam a 'for' inst. Default unroll jam factor is
index aecd4314d424cb0e1f95679d01822e84d1048523..1070c10a2d4d553f485563c57ab30c8d7f02e58e 100644 (file)
@@ -243,7 +243,7 @@ Optional<SmallVector<Value *, 8>> static expandAffineMap(
 
 namespace {
 struct LowerAffinePass : public FunctionPass<LowerAffinePass> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 
   bool lowerAffineFor(OpPointer<AffineForOp> forOp);
   bool lowerAffineIf(AffineIfOp *ifOp);
@@ -604,7 +604,7 @@ bool LowerAffinePass::lowerAffineApply(AffineApplyOp *op) {
 // construction.  When an Value is used, it gets replaced with the
 // corresponding Value that has been defined previously.  The value flow
 // starts with function arguments converted to basic block arguments.
-PassResult LowerAffinePass::runOnFunction() {
+void LowerAffinePass::runOnFunction() {
   SmallVector<Instruction *, 8> instsToRewrite;
 
   // Collect all the For instructions as well as AffineIfOps and AffineApplyOps.
@@ -620,16 +620,14 @@ PassResult LowerAffinePass::runOnFunction() {
   for (auto *inst : instsToRewrite) {
     if (auto ifOp = inst->dyn_cast<AffineIfOp>()) {
       if (lowerAffineIf(ifOp))
-        return failure();
+        return signalPassFailure();
     } else if (auto forOp = inst->dyn_cast<AffineForOp>()) {
       if (lowerAffineFor(forOp))
-        return failure();
+        return signalPassFailure();
     } else if (lowerAffineApply(inst->cast<AffineApplyOp>())) {
-      return failure();
+      return signalPassFailure();
     }
   }
-
-  return success();
 }
 
 /// Lowers If and For instructions within a function into their lower level CFG
index ddeb524f5ab592c5816fdd16d35849130b18a93f..261c360631f10cd3ed0c115a46761c11cda68b64 100644 (file)
@@ -426,11 +426,10 @@ public:
 
 struct LowerVectorTransfersPass
     : public FunctionPass<LowerVectorTransfersPass> {
-  PassResult runOnFunction() {
+  void runOnFunction() {
     Function *f = &getFunction();
     applyMLPatternsGreedily<VectorTransferExpander<VectorTransferReadOp>,
                             VectorTransferExpander<VectorTransferWriteOp>>(f);
-    return success();
   }
 
   // Thread-safe RAII context with local scope. BumpPtrAllocator freed on exit.
index 7b45af011ab24fb49d00140c60f9500a9b140c96..c41c75bb88fab095f72af755e1381394d88ffb80 100644 (file)
@@ -197,7 +197,7 @@ struct MaterializationState {
 };
 
 struct MaterializeVectorsPass : public FunctionPass<MaterializeVectorsPass> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 
 } // end anonymous namespace
@@ -729,14 +729,14 @@ static bool materialize(Function *f,
   return false;
 }
 
-PassResult MaterializeVectorsPass::runOnFunction() {
+void MaterializeVectorsPass::runOnFunction() {
   // Thread-safe RAII local context, BumpPtrAllocator freed on exit.
   NestedPatternContext mlContext;
 
   // TODO(ntv): Check to see if this supports arbitrary top-level code.
   Function *f = &getFunction();
   if (f->getBlocks().size() != 1)
-    return success();
+    return;
 
   using matcher::Op;
   LLVM_DEBUG(dbgs() << "\nMaterializeVectors on Function\n");
@@ -764,8 +764,8 @@ PassResult MaterializeVectorsPass::runOnFunction() {
     terminators.insert(m.getMatchedInstruction());
   }
 
-  auto fail = materialize(f, terminators, &state);
-  return fail ? PassResult::Failure : PassResult::Success;
+  if (materialize(f, terminators, &state))
+    signalPassFailure();
 }
 
 FunctionPassBase *mlir::createMaterializeVectorsPass() {
index 067bfa4c94cc2ce264776838393e9f955c67a5bc..55837f95d14d1fee6da54243e8fb06ceed566c7e 100644 (file)
@@ -70,7 +70,7 @@ namespace {
 // than dealloc) remain.
 //
 struct MemRefDataFlowOpt : public FunctionPass<MemRefDataFlowOpt> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 
   void forwardStoreToLoad(OpPointer<LoadOp> loadOp);
 
@@ -209,11 +209,11 @@ void MemRefDataFlowOpt::forwardStoreToLoad(OpPointer<LoadOp> loadOp) {
   loadOpsToErase.push_back(loadOpInst);
 }
 
-PassResult MemRefDataFlowOpt::runOnFunction() {
+void MemRefDataFlowOpt::runOnFunction() {
   // Only supports single block functions at the moment.
   Function &f = getFunction();
   if (f.getBlocks().size() != 1)
-    return success();
+    return;
 
   DominanceInfo theDomInfo(&f);
   domInfo = &theDomInfo;
@@ -254,9 +254,6 @@ PassResult MemRefDataFlowOpt::runOnFunction() {
       use.getOwner()->erase();
     defInst->erase();
   }
-
-  // This function never leaves the IR in an invalid state.
-  return success();
 }
 
 static PassRegistration<MemRefDataFlowOpt>
index 19d31fd9f26c8f6fdee9eb18e696071f3d4f563e..9df1af9767f41b328df7d8ab76aff10d84ba723f 100644 (file)
@@ -39,8 +39,8 @@ using namespace mlir;
 namespace {
 
 struct PipelineDataTransfer : public FunctionPass<PipelineDataTransfer> {
-  PassResult runOnFunction() override;
-  PassResult runOnAffineForOp(OpPointer<AffineForOp> forOp);
+  void runOnFunction() override;
+  void runOnAffineForOp(OpPointer<AffineForOp> forOp);
 
   std::vector<OpPointer<AffineForOp>> forOps;
 };
@@ -139,7 +139,7 @@ static bool doubleBuffer(Value *oldMemRef, OpPointer<AffineForOp> forOp) {
 }
 
 /// Returns success if the IR is in a valid state.
-PassResult PipelineDataTransfer::runOnFunction() {
+void PipelineDataTransfer::runOnFunction() {
   // Do a post order walk so that inner loop DMAs are processed first. This is
   // necessary since 'for' instructions nested within would otherwise become
   // invalid (erased) when the outer loop is pipelined (the pipelined one gets
@@ -148,11 +148,8 @@ PassResult PipelineDataTransfer::runOnFunction() {
   forOps.clear();
   getFunction().walkPostOrder<AffineForOp>(
       [&](OpPointer<AffineForOp> forOp) { forOps.push_back(forOp); });
-  bool ret = false;
-  for (auto forOp : forOps) {
-    ret = ret | runOnAffineForOp(forOp);
-  }
-  return ret ? failure() : success();
+  for (auto forOp : forOps)
+    runOnAffineForOp(forOp);
 }
 
 // Check if tags of the dma start op and dma wait op match.
@@ -252,13 +249,12 @@ static void findMatchingStartFinishInsts(
 /// Overlap DMA transfers with computation in this loop. If successful,
 /// 'forOp' is deleted, and a prologue, a new pipelined loop, and epilogue are
 /// inserted right before where it was.
-PassResult
-PipelineDataTransfer::runOnAffineForOp(OpPointer<AffineForOp> forOp) {
+void PipelineDataTransfer::runOnAffineForOp(OpPointer<AffineForOp> forOp) {
   auto mayBeConstTripCount = getConstantTripCount(forOp);
   if (!mayBeConstTripCount.hasValue()) {
     LLVM_DEBUG(
         forOp->emitNote("won't pipeline due to unknown trip count loop"));
-    return success();
+    return;
   }
 
   SmallVector<std::pair<Instruction *, Instruction *>, 4> startWaitPairs;
@@ -266,7 +262,7 @@ PipelineDataTransfer::runOnAffineForOp(OpPointer<AffineForOp> forOp) {
 
   if (startWaitPairs.empty()) {
     LLVM_DEBUG(forOp->emitNote("No dma start/finish pairs\n"));
-    return success();
+    return;
   }
 
   // Double the buffers for the higher memory space memref's.
@@ -287,7 +283,7 @@ PipelineDataTransfer::runOnAffineForOp(OpPointer<AffineForOp> forOp) {
       LLVM_DEBUG(llvm::dbgs() << "double buffering failed for: \n";);
       LLVM_DEBUG(dmaStartInst->dump());
       // IR still in a valid state.
-      return success();
+      return;
     }
     // If the old memref has no more uses, remove its 'dead' alloc if it was
     // alloc'ed. (note: DMA buffers are rarely function live-in; but a 'dim'
@@ -315,7 +311,7 @@ PipelineDataTransfer::runOnAffineForOp(OpPointer<AffineForOp> forOp) {
         dmaFinishInst->getOperand(getTagMemRefPos(*dmaFinishInst));
     if (!doubleBuffer(oldTagMemRef, forOp)) {
       LLVM_DEBUG(llvm::dbgs() << "tag double buffering failed\n";);
-      return success();
+      return;
     }
     // If the old tag has no more uses, remove its 'dead' alloc if it was
     // alloc'ed.
@@ -377,15 +373,13 @@ PipelineDataTransfer::runOnAffineForOp(OpPointer<AffineForOp> forOp) {
   if (!isInstwiseShiftValid(forOp, shifts)) {
     // Violates dependences.
     LLVM_DEBUG(llvm::dbgs() << "Shifts invalid - unexpected\n";);
-    return success();
+    return;
   }
 
   if (instBodySkew(forOp, shifts)) {
     LLVM_DEBUG(llvm::dbgs() << "inst body skewing failed - unexpected\n";);
-    return success();
+    return;
   }
-
-  return success();
 }
 
 static PassRegistration<PipelineDataTransfer> pass(
index 4c0fed5b6482ce458fb19d9d41bd6ac14b17237d..3adcbe038ea66d7f7b5a0686fafd24ac317e237f 100644 (file)
@@ -38,7 +38,7 @@ namespace {
 /// on AffineMap and driven from the existing canonicalization pass.
 struct SimplifyAffineStructures
     : public FunctionPass<SimplifyAffineStructures> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 
 } // end anonymous namespace
@@ -57,7 +57,7 @@ static IntegerSet simplifyIntegerSet(IntegerSet set) {
   return set;
 }
 
-PassResult SimplifyAffineStructures::runOnFunction() {
+void SimplifyAffineStructures::runOnFunction() {
   getFunction().walk([&](Instruction *opInst) {
     for (auto attr : opInst->getAttrs()) {
       if (auto mapAttr = attr.second.dyn_cast<AffineMapAttr>()) {
@@ -71,8 +71,6 @@ PassResult SimplifyAffineStructures::runOnFunction() {
       }
     }
   });
-
-  return success();
 }
 
 static PassRegistration<SimplifyAffineStructures>
index 0f1ba02174b7edc7dd1d8d252d9eccc62b9ff983..47244f94ac9facc3141e589d733a79e0d32a35d3 100644 (file)
@@ -24,18 +24,17 @@ using namespace mlir;
 
 namespace {
 struct StripDebugInfo : public FunctionPass<StripDebugInfo> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 } // end anonymous namespace
 
-PassResult StripDebugInfo::runOnFunction() {
+void StripDebugInfo::runOnFunction() {
   Function &func = getFunction();
   UnknownLoc unknownLoc = UnknownLoc::get(func.getContext());
 
   // Strip the debug info from the function and its instructions.
   func.setLoc(unknownLoc);
   func.walk([&](Instruction *inst) { inst->setLoc(unknownLoc); });
-  return success();
 }
 
 /// Creates a pass to strip debug information from a function.
index 60e58c42e6b10c94c045bd88f24cb683cf0bd129..c254790dbe7ad6a1fa658a9d0a10bfc63b1465d6 100644 (file)
@@ -87,7 +87,7 @@ struct VectorizerTestPass : public FunctionPass<VectorizerTestPass> {
   static constexpr auto kTestAffineMapOpName = "test_affine_map";
   static constexpr auto kTestAffineMapAttrName = "affine_map";
 
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
   void testVectorShapeRatio(Function *f);
   void testForwardSlicing(Function *f);
   void testBackwardSlicing(Function *f);
@@ -260,14 +260,14 @@ void VectorizerTestPass::testNormalizeMaps(Function *f) {
   }
 }
 
-PassResult VectorizerTestPass::runOnFunction() {
+void VectorizerTestPass::runOnFunction() {
   // Thread-safe RAII local context, BumpPtrAllocator freed on exit.
   NestedPatternContext mlContext;
 
   // Only support single block functions at this point.
   Function *f = &getFunction();
   if (f->getBlocks().size() != 1)
-    return success();
+    return;
 
   if (!clTestVectorShapeRatio.empty()) {
     testVectorShapeRatio(f);
@@ -287,7 +287,6 @@ PassResult VectorizerTestPass::runOnFunction() {
   if (clTestNormalizeMaps) {
     testNormalizeMaps(f);
   }
-  return PassResult::Success;
 }
 
 FunctionPassBase *mlir::createVectorizerTestPass() {
index 8a378a29c848a268f66331f5a1851bfd009a6464..50c6cdad0f953d8e1fe67fad2c3f40da088e6663 100644 (file)
@@ -652,7 +652,7 @@ static std::vector<NestedPattern> makePatterns() {
 namespace {
 
 struct Vectorize : public FunctionPass<Vectorize> {
-  PassResult runOnFunction() override;
+  void runOnFunction() override;
 };
 
 } // end anonymous namespace
@@ -1260,7 +1260,7 @@ static bool vectorizeRootMatch(NestedMatch m, VectorizationStrategy *strategy) {
 
 /// Applies vectorization to the current Function by searching over a bunch of
 /// predetermined patterns.
-PassResult Vectorize::runOnFunction() {
+void Vectorize::runOnFunction() {
   // Thread-safe RAII local context, BumpPtrAllocator freed on exit.
   NestedPatternContext mlContext;
 
@@ -1295,7 +1295,6 @@ PassResult Vectorize::runOnFunction() {
     }
   }
   LLVM_DEBUG(dbgs() << "\n");
-  return PassResult::Success;
 }
 
 FunctionPassBase *mlir::createVectorizePass() { return new Vectorize(); }
index 30fae94139ffaa6220bdf58c73f88e89d9c77446..b2dfe6795b6f3b85939ba4b41520465fd1883e39 100644 (file)
@@ -77,9 +77,8 @@ struct PrintCFGPass : public FunctionPass<PrintCFGPass> {
   PrintCFGPass(llvm::raw_ostream &os = llvm::errs(), bool shortNames = false,
                const llvm::Twine &title = "")
       : os(os), shortNames(shortNames), title(title) {}
-  PassResult runOnFunction() {
+  void runOnFunction() {
     mlir::writeGraph(os, &getFunction(), shortNames, title);
-    return success();
   }
 
 private:
index 96c85b237198e09665fb8807b7759e04e69c59c6..2b9af3debc1e8ddacc984542927fb5c67928b95b 100644 (file)
@@ -131,7 +131,7 @@ static OptResult performActions(SourceMgr &sourceMgr, MLIRContext *context) {
   PassManager pm;
   for (const auto *passEntry : *passList)
     passEntry->addToPipeline(pm);
-  if (pm.run(module.get()))
+  if (!pm.run(module.get()))
     return OptFailure;
 
   std::string errorMessage;