2019-03-11 06:44:47 +08:00
|
|
|
//===- PassDetail.h - MLIR Pass details -------------------------*- C++ -*-===//
|
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-03-11 06:44:47 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-03-11 06:44:47 +08:00
|
|
|
#ifndef MLIR_PASS_PASSDETAIL_H_
|
|
|
|
#define MLIR_PASS_PASSDETAIL_H_
|
|
|
|
|
|
|
|
#include "mlir/Pass/Pass.h"
|
2019-09-10 00:51:59 +08:00
|
|
|
#include "mlir/Pass/PassManager.h"
|
2019-03-11 06:44:47 +08:00
|
|
|
|
|
|
|
namespace mlir {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2019-09-03 10:24:47 +08:00
|
|
|
// OpToOpPassAdaptor
|
2019-03-11 06:44:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-04-30 06:08:05 +08:00
|
|
|
/// An adaptor pass used to run operation passes over nested operations.
|
2020-04-08 04:56:16 +08:00
|
|
|
class OpToOpPassAdaptor
|
2020-04-30 06:08:05 +08:00
|
|
|
: public PassWrapper<OpToOpPassAdaptor, OperationPass<>> {
|
2019-03-11 06:44:47 +08:00
|
|
|
public:
|
2019-09-10 00:51:59 +08:00
|
|
|
OpToOpPassAdaptor(OpPassManager &&mgr);
|
2020-04-30 06:08:05 +08:00
|
|
|
OpToOpPassAdaptor(const OpToOpPassAdaptor &rhs) = default;
|
2019-03-11 06:44:47 +08:00
|
|
|
|
2019-09-03 10:24:47 +08:00
|
|
|
/// Run the held pipeline over all operations.
|
2020-11-03 19:17:01 +08:00
|
|
|
void runOnOperation(bool verifyPasses);
|
2019-09-03 10:24:47 +08:00
|
|
|
void runOnOperation() override;
|
2019-03-11 06:44:47 +08:00
|
|
|
|
2020-04-30 06:08:05 +08:00
|
|
|
/// Merge the current pass adaptor into given 'rhs'.
|
|
|
|
void mergeInto(OpToOpPassAdaptor &rhs);
|
2019-03-27 12:15:54 +08:00
|
|
|
|
2020-04-30 06:08:05 +08:00
|
|
|
/// Returns the pass managers held by this adaptor.
|
|
|
|
MutableArrayRef<OpPassManager> getPassManagers() { return mgrs; }
|
2019-03-11 06:44:47 +08:00
|
|
|
|
Separate the Registration from Loading dialects in the Context
This changes the behavior of constructing MLIRContext to no longer load globally
registered dialects on construction. Instead Dialects are only loaded explicitly
on demand:
- the Parser is lazily loading Dialects in the context as it encounters them
during parsing. This is the only purpose for registering dialects and not load
them in the context.
- Passes are expected to declare the dialects they will create entity from
(Operations, Attributes, or Types), and the PassManager is loading Dialects into
the Context when starting a pipeline.
This changes simplifies the configuration of the registration: a compiler only
need to load the dialect for the IR it will emit, and the optimizer is
self-contained and load the required Dialects. For example in the Toy tutorial,
the compiler only needs to load the Toy dialect in the Context, all the others
(linalg, affine, std, LLVM, ...) are automatically loaded depending on the
optimization pipeline enabled.
To adjust to this change, stop using the existing dialect registration: the
global registry will be removed soon.
1) For passes, you need to override the method:
virtual void getDependentDialects(DialectRegistry ®istry) const {}
and registery on the provided registry any dialect that this pass can produce.
Passes defined in TableGen can provide this list in the dependentDialects list
field.
2) For dialects, on construction you can register dependent dialects using the
provided MLIRContext: `context.getOrLoadDialect<DialectName>()`
This is useful if a dialect may canonicalize or have interfaces involving
another dialect.
3) For loading IR, dialect that can be in the input file must be explicitly
registered with the context. `MlirOptMain()` is taking an explicit registry for
this purpose. See how the standalone-opt.cpp example is setup:
mlir::DialectRegistry registry;
registry.insert<mlir::standalone::StandaloneDialect>();
registry.insert<mlir::StandardOpsDialect>();
Only operations from these two dialects can be in the input file. To include all
of the dialects in MLIR Core, you can populate the registry this way:
mlir::registerAllDialects(registry);
4) For `mlir-translate` callback, as well as frontend, Dialects can be loaded in
the context before emitting the IR: context.getOrLoadDialect<ToyDialect>()
Differential Revision: https://reviews.llvm.org/D85622
2020-08-19 04:01:19 +08:00
|
|
|
/// Populate the set of dependent dialects for the passes in the current
|
|
|
|
/// adaptor.
|
|
|
|
void getDependentDialects(DialectRegistry &dialects) const override;
|
|
|
|
|
2019-12-06 03:52:58 +08:00
|
|
|
/// Return the async pass managers held by this parallel adaptor.
|
|
|
|
MutableArrayRef<SmallVector<OpPassManager, 1>> getParallelPassManagers() {
|
|
|
|
return asyncExecutors;
|
|
|
|
}
|
|
|
|
|
2020-04-30 06:08:05 +08:00
|
|
|
/// Returns the adaptor pass name.
|
|
|
|
std::string getAdaptorName();
|
|
|
|
|
2019-03-11 06:44:47 +08:00
|
|
|
private:
|
2020-04-30 06:08:05 +08:00
|
|
|
/// Run this pass adaptor synchronously.
|
2020-11-03 19:17:01 +08:00
|
|
|
void runOnOperationImpl(bool verifyPasses);
|
2020-04-30 06:08:05 +08:00
|
|
|
|
|
|
|
/// Run this pass adaptor asynchronously.
|
2020-11-03 19:17:01 +08:00
|
|
|
void runOnOperationAsyncImpl(bool verifyPasses);
|
2019-03-11 06:44:47 +08:00
|
|
|
|
2020-08-27 12:42:38 +08:00
|
|
|
/// Run the given operation and analysis manager on a single pass.
|
2021-01-09 05:24:07 +08:00
|
|
|
/// `parentInitGeneration` is the initialization generation of the parent pass
|
|
|
|
/// manager, and is used to initialize any dynamic pass pipelines run by the
|
|
|
|
/// given pass.
|
2020-11-03 19:17:01 +08:00
|
|
|
static LogicalResult run(Pass *pass, Operation *op, AnalysisManager am,
|
2021-01-09 05:24:07 +08:00
|
|
|
bool verifyPasses, unsigned parentInitGeneration);
|
2020-08-27 12:42:38 +08:00
|
|
|
|
|
|
|
/// Run the given operation and analysis manager on a provided op pass
|
2021-01-09 05:24:07 +08:00
|
|
|
/// manager. `parentInitGeneration` is the initialization generation of the
|
|
|
|
/// parent pass manager, and is used to initialize any dynamic pass pipelines
|
|
|
|
/// run by the given passes.
|
2020-12-15 10:07:45 +08:00
|
|
|
static LogicalResult runPipeline(
|
|
|
|
iterator_range<OpPassManager::pass_iterator> passes, Operation *op,
|
2021-01-09 05:24:07 +08:00
|
|
|
AnalysisManager am, bool verifyPasses, unsigned parentInitGeneration,
|
2020-12-15 10:07:45 +08:00
|
|
|
PassInstrumentor *instrumentor = nullptr,
|
|
|
|
const PassInstrumentation::PipelineParentInfo *parentInfo = nullptr);
|
2020-08-27 12:42:38 +08:00
|
|
|
|
2020-04-30 06:08:05 +08:00
|
|
|
/// A set of adaptors to run.
|
|
|
|
SmallVector<OpPassManager, 1> mgrs;
|
2019-09-10 00:51:59 +08:00
|
|
|
|
2020-04-30 06:08:05 +08:00
|
|
|
/// A set of executors, cloned from the main executor, that run asynchronously
|
|
|
|
/// on different threads. This is used when threading is enabled.
|
|
|
|
SmallVector<SmallVector<OpPassManager, 1>, 8> asyncExecutors;
|
2020-08-27 12:42:38 +08:00
|
|
|
|
|
|
|
// For accessing "runPipeline".
|
|
|
|
friend class mlir::PassManager;
|
2020-04-30 06:08:05 +08:00
|
|
|
};
|
2019-03-27 12:15:54 +08:00
|
|
|
|
2019-03-11 06:44:47 +08:00
|
|
|
} // end namespace detail
|
|
|
|
} // end namespace mlir
|
|
|
|
#endif // MLIR_PASS_PASSDETAIL_H_
|