2019-03-11 06:44:47 +08:00
|
|
|
//===- PassDetail.h - MLIR Pass details -------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Copyright 2019 The MLIR Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// =============================================================================
|
|
|
|
#ifndef MLIR_PASS_PASSDETAIL_H_
|
|
|
|
#define MLIR_PASS_PASSDETAIL_H_
|
|
|
|
|
|
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
|
|
|
|
namespace mlir {
|
2019-09-03 10:24:47 +08:00
|
|
|
class OpPassManager;
|
|
|
|
|
2019-03-11 06:44:47 +08:00
|
|
|
namespace detail {
|
|
|
|
|
2019-07-13 02:20:09 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-09-03 10:24:47 +08:00
|
|
|
// Verifier Pass
|
2019-07-13 02:20:09 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Pass to verify an operation and signal failure if necessary.
|
|
|
|
class VerifierPass : public OperationPass<VerifierPass> {
|
|
|
|
void runOnOperation() override;
|
2019-07-13 02:20:09 +08:00
|
|
|
};
|
|
|
|
|
2019-03-11 06:44:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-09-03 10:24:47 +08:00
|
|
|
// OpToOpPassAdaptor
|
2019-03-11 06:44:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// An adaptor pass used to run operation passes over nested operations
|
|
|
|
/// synchronously on a single thread.
|
|
|
|
class OpToOpPassAdaptor : public OperationPass<OpToOpPassAdaptor> {
|
2019-03-11 06:44:47 +08:00
|
|
|
public:
|
2019-09-03 10:24:47 +08:00
|
|
|
OpToOpPassAdaptor(std::unique_ptr<OpPassManager> mgr);
|
|
|
|
OpToOpPassAdaptor(const OpToOpPassAdaptor &rhs);
|
2019-03-11 06:44:47 +08:00
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Run the held pipeline over all operations.
|
|
|
|
void runOnOperation() override;
|
2019-03-11 06:44:47 +08:00
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Returns the nested pass manager for this adaptor.
|
|
|
|
OpPassManager &getPassManager() { return *mgr; }
|
2019-03-11 06:44:47 +08:00
|
|
|
|
|
|
|
private:
|
2019-09-03 10:24:47 +08:00
|
|
|
std::unique_ptr<OpPassManager> mgr;
|
2019-03-11 06:44:47 +08:00
|
|
|
};
|
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// An adaptor pass used to run operation passes over nested operations
|
|
|
|
/// asynchronously across multiple threads.
|
|
|
|
class OpToOpPassAdaptorParallel
|
|
|
|
: public OperationPass<OpToOpPassAdaptorParallel> {
|
2019-03-11 06:44:47 +08:00
|
|
|
public:
|
2019-09-03 10:24:47 +08:00
|
|
|
OpToOpPassAdaptorParallel(std::unique_ptr<OpPassManager> mgr);
|
|
|
|
OpToOpPassAdaptorParallel(const OpToOpPassAdaptorParallel &rhs);
|
2019-03-27 12:15:54 +08:00
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Run the held pipeline over all operations.
|
|
|
|
void runOnOperation() override;
|
2019-03-11 06:44:47 +08:00
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Returns the nested pass manager for this adaptor.
|
|
|
|
OpPassManager &getPassManager() { return *mgr; }
|
2019-03-11 06:44:47 +08:00
|
|
|
|
|
|
|
private:
|
2019-09-03 10:24:47 +08:00
|
|
|
// The main pass executor for this adaptor.
|
|
|
|
std::unique_ptr<OpPassManager> mgr;
|
2019-03-27 12:15:54 +08:00
|
|
|
|
|
|
|
// A set of executors, cloned from the main executor, that run asynchronously
|
|
|
|
// on different threads.
|
2019-09-03 10:24:47 +08:00
|
|
|
std::vector<OpPassManager> asyncExecutors;
|
2019-03-11 06:44:47 +08:00
|
|
|
};
|
|
|
|
|
2019-09-09 10:57:25 +08:00
|
|
|
/// Utility function to return if a pass refers to an adaptor pass. Adaptor
|
|
|
|
/// passes are those that internally execute a pipeline.
|
|
|
|
inline bool isAdaptorPass(Pass *pass) {
|
2019-09-03 10:24:47 +08:00
|
|
|
return isa<OpToOpPassAdaptorParallel>(pass) || isa<OpToOpPassAdaptor>(pass);
|
2019-03-27 12:15:54 +08:00
|
|
|
}
|
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Utility function to return the operation name that the given adaptor pass
|
|
|
|
/// operates on. Return None if the given pass is not an adaptor pass.
|
|
|
|
Optional<StringRef> getAdaptorPassOpName(Pass *pass);
|
2019-07-13 02:20:09 +08:00
|
|
|
|
2019-03-11 06:44:47 +08:00
|
|
|
} // end namespace detail
|
|
|
|
} // end namespace mlir
|
|
|
|
#endif // MLIR_PASS_PASSDETAIL_H_
|