Skip to content

Commit

Permalink
NFC: Finish replacing FunctionPassBase/ModulePassBase with OpPassBase.
Browse files Browse the repository at this point in the history
These directives were temporary during the generalization of FunctionPass/ModulePass to OpPass.

PiperOrigin-RevId: 268970259
  • Loading branch information
River707 authored and tensorflower-gardener committed Sep 13, 2019
1 parent a260436 commit f1b100c
Show file tree
Hide file tree
Showing 69 changed files with 119 additions and 133 deletions.
3 changes: 1 addition & 2 deletions mlir/examples/Linalg/Linalg1/include/linalg1/Passes.h
Expand Up @@ -29,12 +29,11 @@
namespace mlir {
class ModuleOp;
template <typename T> class OpPassBase;
using ModulePassBase = OpPassBase<ModuleOp>;
} // namespace mlir

namespace linalg {

mlir::ModulePassBase *createLowerLinalgToLLVMPass();
mlir::OpPassBase<mlir::ModuleOp> *createLowerLinalgToLLVMPass();

} // namespace linalg

Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/Linalg/Linalg1/lib/ConvertToLLVMDialect.cpp
Expand Up @@ -440,7 +440,7 @@ struct LowerLinalgToLLVMPass : public ModulePass<LowerLinalgToLLVMPass> {
};
} // namespace

ModulePassBase *linalg::createLowerLinalgToLLVMPass() {
OpPassBase<ModuleOp> *linalg::createLowerLinalgToLLVMPass() {
return new LowerLinalgToLLVMPass();
}

Expand Down
4 changes: 2 additions & 2 deletions mlir/examples/Linalg/Linalg3/include/linalg3/Transforms.h
Expand Up @@ -31,7 +31,6 @@ class Operation;
class Value;

template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;
} // namespace mlir

namespace linalg {
Expand Down Expand Up @@ -75,7 +74,8 @@ void lowerToLoops(mlir::FuncOp f);

/// Creates a pass that rewrites linalg.load and linalg.store to affine.load and
/// affine.store operations.
std::unique_ptr<mlir::FunctionPassBase> createLowerLinalgLoadStorePass();
std::unique_ptr<mlir::OpPassBase<mlir::FuncOp>>
createLowerLinalgLoadStorePass();

} // namespace linalg

Expand Down
2 changes: 1 addition & 1 deletion mlir/examples/Linalg/Linalg3/lib/Transforms.cpp
Expand Up @@ -300,6 +300,6 @@ Rewriter<linalg::StoreOp>::matchAndRewrite(linalg::StoreOp store,
}
} // namespace

std::unique_ptr<FunctionPassBase> linalg::createLowerLinalgLoadStorePass() {
std::unique_ptr<OpPassBase<FuncOp>> linalg::createLowerLinalgLoadStorePass() {
return std::make_unique<LowerLinalgLoadStorePass>();
}
8 changes: 4 additions & 4 deletions mlir/include/mlir/Analysis/Passes.h
Expand Up @@ -24,21 +24,21 @@
#define MLIR_ANALYSIS_PASSES_H

#include "mlir/Support/LLVM.h"
#include <memory>

namespace mlir {

class FuncOp;
template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;

/// Creates a pass to check memref accesses in a Function.
FunctionPassBase *createMemRefBoundCheckPass();
std::unique_ptr<OpPassBase<FuncOp>> createMemRefBoundCheckPass();

/// Creates a pass to check memref access dependences in a Function.
FunctionPassBase *createTestMemRefDependenceCheckPass();
std::unique_ptr<OpPassBase<FuncOp>> createTestMemRefDependenceCheckPass();

/// Creates a pass to test parallelism detection; emits note for parallel loops.
FunctionPassBase *createParallelismDetectionTestPass();
std::unique_ptr<OpPassBase<FuncOp>> createParallelismDetectionTestPass();

} // end namespace mlir

Expand Down
Expand Up @@ -26,7 +26,6 @@ class FuncOp;
struct LogicalResult;
class MLIRContext;
template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;
class RewritePattern;

// Owning list of rewriting patterns.
Expand All @@ -39,7 +38,7 @@ void populateLoopToStdConversionPatterns(OwningRewritePatternList &patterns,
MLIRContext *ctx);

/// Creates a pass to convert loop.for, loop.if and loop.terminator ops to CFG.
std::unique_ptr<FunctionPassBase> createLowerToCFGPass();
std::unique_ptr<OpPassBase<FuncOp>> createLowerToCFGPass();

} // namespace mlir

Expand Down
8 changes: 4 additions & 4 deletions mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h
Expand Up @@ -36,7 +36,6 @@ class LLVMDialect;
}

template <typename T> class OpPassBase;
using ModulePassBase = OpPassBase<ModuleOp>;

using OwnedCubin = std::unique_ptr<std::vector<char>>;
using CubinGenerator = std::function<OwnedCubin(const std::string &, FuncOp &)>;
Expand All @@ -50,7 +49,7 @@ using CubinGenerator = std::function<OwnedCubin(const std::string &, FuncOp &)>;
/// attached as a string attribute named 'nvvm.cubin' to the kernel function.
/// After the transformation, the body of the kernel function is removed (i.e.,
/// it is turned into a declaration).
std::unique_ptr<ModulePassBase>
std::unique_ptr<OpPassBase<ModuleOp>>
createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator);

/// Creates a pass to convert a gpu.launch_func operation into a sequence of
Expand All @@ -59,11 +58,12 @@ createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator);
/// This pass does not generate code to call CUDA directly but instead uses a
/// small wrapper library that exports a stable and conveniently typed ABI
/// ontop of CUDA.
std::unique_ptr<ModulePassBase> createConvertGpuLaunchFuncToCudaCallsPass();
std::unique_ptr<OpPassBase<ModuleOp>>
createConvertGpuLaunchFuncToCudaCallsPass();

/// Creates a pass to augment a module with getter functions for all contained
/// cubins as encoded via the 'nvvm.cubin' attribute.
std::unique_ptr<ModulePassBase> createGenerateCubinAccessorPass();
std::unique_ptr<OpPassBase<ModuleOp>> createGenerateCubinAccessorPass();

} // namespace mlir

Expand Down
3 changes: 1 addition & 2 deletions mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h
Expand Up @@ -25,14 +25,13 @@ class OwningRewritePatternList;

class ModuleOp;
template <typename OpT> class OpPassBase;
using ModulePassBase = OpPassBase<ModuleOp>;

/// Collect a set of patterns to convert from the GPU dialect to NVVM.
void populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns);

/// Creates a pass that lowers GPU dialect operations to NVVM counterparts.
std::unique_ptr<ModulePassBase> createLowerGpuOpsToNVVMOpsPass();
std::unique_ptr<OpPassBase<ModuleOp>> createLowerGpuOpsToNVVMOpsPass();

} // namespace mlir

Expand Down
3 changes: 1 addition & 2 deletions mlir/include/mlir/Conversion/LoopsToGPU/LoopsToGPUPass.h
Expand Up @@ -22,7 +22,6 @@
namespace mlir {
class FuncOp;
template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;

/// Create a pass that converts loop nests into GPU kernels. It considers
/// top-level affine.for and linalg.for operations as roots of loop nests and
Expand All @@ -32,7 +31,7 @@ using FunctionPassBase = OpPassBase<FuncOp>;
/// parallelization is performed, it is under the responsibility of the caller
/// to strip-mine the loops and to perform the dependence analysis before
/// calling the conversion.
std::unique_ptr<FunctionPassBase>
std::unique_ptr<OpPassBase<FuncOp>>
createSimpleLoopsToGPUPass(unsigned numBlockDims, unsigned numThreadDims);
} // namespace mlir

Expand Down
Expand Up @@ -34,7 +34,6 @@ struct LogicalResult;
class MLIRContext;
class ModuleOp;
template <typename T> class OpPassBase;
using ModulePassBase = OpPassBase<ModuleOp>;
class RewritePattern;
class Type;

Expand All @@ -58,12 +57,12 @@ void populateStdToLLVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns);

/// Creates a pass to convert the Standard dialect into the LLVMIR dialect.
std::unique_ptr<ModulePassBase> createLowerToLLVMPass();
std::unique_ptr<OpPassBase<ModuleOp>> createLowerToLLVMPass();

/// Creates a pass to convert operations to the LLVMIR dialect. The conversion
/// is defined by a list of patterns and a type converter that will be obtained
/// during the pass using the provided callbacks.
std::unique_ptr<ModulePassBase>
std::unique_ptr<OpPassBase<ModuleOp>>
createLowerToLLVMPass(LLVMPatternListFiller patternListFiller,
LLVMTypeConverterMaker typeConverterMaker);

Expand All @@ -72,7 +71,7 @@ createLowerToLLVMPass(LLVMPatternListFiller patternListFiller,
/// callback and an optional type conversion class, an instance is created
/// during the pass.
template <typename TypeConverter = LLVMTypeConverter>
std::unique_ptr<ModulePassBase>
std::unique_ptr<OpPassBase<ModuleOp>>
createLowerToLLVMPass(LLVMPatternListFiller patternListFiller) {
return createLowerToLLVMPass(patternListFiller, [](MLIRContext *context) {
return std::make_unique<TypeConverter>(context);
Expand Down
3 changes: 1 addition & 2 deletions mlir/include/mlir/Conversion/VectorToLLVM/VectorToLLVM.h
Expand Up @@ -23,14 +23,13 @@ class ModuleOp;
class OwningRewritePatternList;

template <typename T> class OpPassBase;
using ModulePassBase = OpPassBase<ModuleOp>;

/// Collect a set of patterns to convert from the Vector dialect to LLVM.
void populateVectorToLLVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns);

/// Create a pass to convert vector operations to the LLVMIR dialect.
ModulePassBase *createLowerVectorToLLVMPass();
OpPassBase<ModuleOp> *createLowerVectorToLLVMPass();
} // namespace mlir

#endif // MLIR_CONVERSION_VECTORTOLLVM_VECTORTOLLVM_H_
5 changes: 2 additions & 3 deletions mlir/include/mlir/Dialect/FxpMathOps/Passes.h
Expand Up @@ -25,19 +25,18 @@
namespace mlir {
class FuncOp;
template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;

namespace fxpmath {

/// Creates a pass that lowers uniform-quantized real math ops to integer
/// arithmetic. This will leave unrecognized real math ops as-is and is
/// typically followed by a pass that lowers any unrecognized ops to a pure
/// floating point form.
FunctionPassBase *createLowerUniformRealMathPass();
OpPassBase<FuncOp> *createLowerUniformRealMathPass();

/// Creates a pass that lowers uniform-quantized qcast/dcast ops to equivalent
/// operations that perform quantize/dequantize.
FunctionPassBase *createLowerUniformCastsPass();
OpPassBase<FuncOp> *createLowerUniformCastsPass();

} // namespace fxpmath
} // namespace mlir
Expand Down
3 changes: 1 addition & 2 deletions mlir/include/mlir/Dialect/GPU/Passes.h
Expand Up @@ -28,9 +28,8 @@ namespace mlir {

class ModuleOp;
template <typename T> class OpPassBase;
using ModulePassBase = OpPassBase<ModuleOp>;

std::unique_ptr<ModulePassBase> createGpuKernelOutliningPass();
std::unique_ptr<OpPassBase<ModuleOp>> createGpuKernelOutliningPass();

} // namespace mlir

Expand Down
10 changes: 4 additions & 6 deletions mlir/include/mlir/Dialect/Linalg/Passes.h
Expand Up @@ -29,20 +29,18 @@ namespace mlir {
class FuncOp;
class ModuleOp;
template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;
using ModulePassBase = OpPassBase<ModuleOp>;

namespace linalg {
std::unique_ptr<FunctionPassBase>
std::unique_ptr<OpPassBase<FuncOp>>
createLinalgFusionPass(ArrayRef<int64_t> tileSizes = {});

std::unique_ptr<FunctionPassBase>
std::unique_ptr<OpPassBase<FuncOp>>
createLinalgTilingPass(ArrayRef<int64_t> tileSizes = {},
bool promoteViews = false);

std::unique_ptr<FunctionPassBase> createLowerLinalgToLoopsPass();
std::unique_ptr<OpPassBase<FuncOp>> createLowerLinalgToLoopsPass();

std::unique_ptr<ModulePassBase> createLowerLinalgToLLVMPass();
std::unique_ptr<OpPassBase<ModuleOp>> createLowerLinalgToLLVMPass();
} // namespace linalg
} // namespace mlir

Expand Down
5 changes: 2 additions & 3 deletions mlir/include/mlir/Dialect/QuantOps/Passes.h
Expand Up @@ -30,20 +30,19 @@
namespace mlir {
class FuncOp;
template <typename T> class OpPassBase;
using FunctionPassBase = OpPassBase<FuncOp>;

namespace quant {

/// Creates a pass that converts quantization simulation operations (i.e.
/// FakeQuant and those like it) to casts into/out of supported QuantizedTypes.
std::unique_ptr<FunctionPassBase> createConvertSimulatedQuantPass();
std::unique_ptr<OpPassBase<FuncOp>> createConvertSimulatedQuantPass();

/// Creates a pass that converts constants followed by a qbarrier to a
/// constant whose value is quantized. This is typically one of the last
/// passes done when lowering to express actual quantized arithmetic in a
/// low level representation. Because it modifies the constant, it is
/// destructive and cannot be undone.
std::unique_ptr<FunctionPassBase> createConvertConstPass();
std::unique_ptr<OpPassBase<FuncOp>> createConvertConstPass();

} // namespace quant
} // namespace mlir
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/SPIRV/Passes.h
Expand Up @@ -27,7 +27,7 @@
namespace mlir {
namespace spirv {

std::unique_ptr<ModulePassBase> createConvertStandardToSPIRVPass();
std::unique_ptr<OpPassBase<mlir::ModuleOp>> createConvertStandardToSPIRVPass();

} // namespace spirv
} // namespace mlir
Expand Down
5 changes: 0 additions & 5 deletions mlir/include/mlir/Pass/Pass.h
Expand Up @@ -298,11 +298,6 @@ template <typename T> struct ModulePass : public OpPass<ModuleOp, T> {
/// Return the current module being transformed.
ModuleOp getModule() { return this->getOperation(); }
};

/// Using directives defining legacy base classes.
// TODO(riverriddle) These should be removed in favor of OpPassBase<T>.
using FunctionPassBase = OpPassBase<FuncOp>;
using ModulePassBase = OpPassBase<ModuleOp>;
} // end namespace mlir

#endif // MLIR_PASS_PASS_H
6 changes: 3 additions & 3 deletions mlir/include/mlir/Quantizer/Transforms/Passes.h
Expand Up @@ -33,17 +33,17 @@ class TargetConfiguration;

/// Creates a pass that infers quantized types based on metadata discovered
/// in the computation.
std::unique_ptr<ModulePassBase>
std::unique_ptr<OpPassBase<ModuleOp>>
createInferQuantizedTypesPass(SolverContext &solverContext,
const TargetConfiguration &config);

/// Creates a pass which removes any instrumentation and hint ops which have
/// no effect on final runtime.
std::unique_ptr<FunctionPassBase> createRemoveInstrumentationPass();
std::unique_ptr<OpPassBase<FuncOp>> createRemoveInstrumentationPass();

/// Adds default (dummy) statistics to ops that can benefit from runtime stats.
/// Meant for testing.
std::unique_ptr<FunctionPassBase> createAddDefaultStatsPass();
std::unique_ptr<OpPassBase<FuncOp>> createAddDefaultStatsPass();

} // namespace quantizer
} // namespace mlir
Expand Down

0 comments on commit f1b100c

Please sign in to comment.