Skip to content

Commit

Permalink
NFC: Merge OpPass with OperationPass into just OperationPass.
Browse files Browse the repository at this point in the history
OperationPass' are defined exactly the same way as they are now:
   class DerivedPass :  public OperationPass<DerivedPass>;

OpPass' are now defined as OperationPass, but with an additional template parameter for the operation type:
   class DerivedPass :  public OperationPass<DerivedPass, FuncOp>;

PiperOrigin-RevId: 269122410
  • Loading branch information
River707 authored and tensorflower-gardener committed Sep 15, 2019
1 parent 38e7226 commit cb1bcba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
36 changes: 15 additions & 21 deletions mlir/include/mlir/Pass/Pass.h
Expand Up @@ -227,7 +227,7 @@ template <typename OpT> class OpPassBase : public Pass {
}
};

/// Pass to transform an operation.
/// Pass to transform an operation of a specific type.
///
/// Operation passes must not:
/// - modify any other operations within the parent region, as other threads
Expand All @@ -237,10 +237,17 @@ template <typename OpT> class OpPassBase : public Pass {
///
/// Derived function passes are expected to provide the following:
/// - A 'void runOnOperation()' method.
template <typename T>
struct OperationPass : public detail::PassModel<T, Pass> {};
template <typename PassT, typename OpT = void>
class OperationPass : public detail::PassModel<PassT, OpPassBase<OpT>> {
protected:
OperationPass()
: detail::PassModel<PassT, OpPassBase<OpT>>(OpT::getOperationName()) {}

/// Pass to transform an operation of a specific type.
/// Return the current operation being transformed.
OpT getOperation() { return cast<OpT>(Pass::getOperation()); }
};

/// Pass to transform an operation.
///
/// Operation passes must not:
/// - modify any other operations within the parent region, as other threads
Expand All @@ -250,27 +257,14 @@ struct OperationPass : public detail::PassModel<T, Pass> {};
///
/// Derived function passes are expected to provide the following:
/// - A 'void runOnOperation()' method.
template <typename OpT, typename PassT>
class OpPass : public detail::PassModel<PassT, OpPassBase<OpT>> {
protected:
OpPass()
: detail::PassModel<PassT, OpPassBase<OpT>>(OpT::getOperationName()) {}

/// Return the current operation being transformed.
OpT getOperation() { return cast<OpT>(Pass::getOperation()); }
};
template <typename PassT>
struct OperationPass<PassT, void> : public detail::PassModel<PassT, Pass> {};

/// A model for providing function pass specific utilities.
///
/// Function passes must not:
/// - read or modify any other functions within the parent module, as
/// other threads may be manipulating them concurrently.
/// - modify any state within the parent module, this includes adding
/// additional functions.
///
/// Derived function passes are expected to provide the following:
/// - A 'void runOnFunction()' method.
template <typename T> struct FunctionPass : public OpPass<FuncOp, T> {
template <typename T> struct FunctionPass : public OperationPass<T, FuncOp> {
/// The polymorphic API that runs the pass over the currently held function.
virtual void runOnFunction() = 0;

Expand All @@ -288,7 +282,7 @@ template <typename T> struct FunctionPass : public OpPass<FuncOp, T> {
///
/// Derived module passes are expected to provide the following:
/// - A 'void runOnModule()' method.
template <typename T> struct ModulePass : public OpPass<ModuleOp, T> {
template <typename T> struct ModulePass : public OperationPass<T, ModuleOp> {
/// The polymorphic API that runs the pass over the currently held module.
virtual void runOnModule() = 0;

Expand Down
5 changes: 2 additions & 3 deletions mlir/include/mlir/Pass/PassManager.h
Expand Up @@ -64,9 +64,8 @@ class OpPassManager {
return nest(OpT::getOperationName());
}

/// Add the given pass to this pass manager. The pass must either be an opaque
/// `OperationPass`, or an `OpPass` that operates on operations of the same
/// type as this pass manager.
/// Add the given pass to this pass manager. If this pass has a concrete
/// operation type, it must be the same type as this pass manager.
void addPass(std::unique_ptr<Pass> pass);

/// Returns the number of passes held by this manager.
Expand Down
5 changes: 2 additions & 3 deletions mlir/lib/Pass/Pass.cpp
Expand Up @@ -225,9 +225,8 @@ OpPassManager &OpPassManager::nest(StringRef nestedName) {
return nest(OperationName(nestedName, getContext()));
}

/// Add the given pass to this pass manager. The pass must either be an opaque
/// `OperationPass`, or an `OpPass` that operates on operations of the same
/// type as this pass manager.
/// Add the given pass to this pass manager. If this pass has a concrete
/// operation type, it must be the same type as this pass manager.
void OpPassManager::addPass(std::unique_ptr<Pass> pass) {
// If this pass runs on a different operation than this pass manager, then
// implicitly nest a pass manager for this operation.
Expand Down

0 comments on commit cb1bcba

Please sign in to comment.