NFC: Rename Module to ModuleOp.

Module is a legacy name that only exists as a typedef of ModuleOp.

PiperOrigin-RevId: 257427248
This commit is contained in:
River Riddle 2019-07-10 10:07:49 -07:00 committed by jpienaar
parent 6b6dc59f30
commit fec20e590f
53 changed files with 110 additions and 123 deletions

View File

@ -147,7 +147,7 @@ struct PythonFunction {
struct PythonMLIRModule {
PythonMLIRModule()
: mlirContext(),
module(mlir::Module::create(mlir::UnknownLoc::get(&mlirContext))),
module(mlir::ModuleOp::create(mlir::UnknownLoc::get(&mlirContext))),
moduleManager(*module) {}
PythonType makeScalarType(const std::string &mlirElemType,
@ -756,7 +756,8 @@ PYBIND11_MODULE(pybind, m) {
py::class_<PythonMLIRModule>(
m, "MLIRModule",
"An MLIRModule is the abstraction that owns the allocations to support "
"compilation of a single mlir::Module into an ExecutionEngine backed by "
"compilation of a single mlir::ModuleOp into an ExecutionEngine backed "
"by "
"the LLVM ORC JIT. A typical flow consists in creating an MLIRModule, "
"adding functions, compiling the module to obtain an ExecutionEngine on "
"which named functions may be called. For now the only means to retrieve "
@ -773,13 +774,13 @@ PYBIND11_MODULE(pybind, m) {
"Creates an mlir::IntegerAttr of the given type with the given value "
"in the context associated with this MLIR module.")
.def("declare_function", &PythonMLIRModule::declareFunction,
"Declares a new mlir::FuncOp in the current mlir::Module. The "
"Declares a new mlir::FuncOp in the current mlir::ModuleOp. The "
"function arguments can have attributes. The function has no "
"definition and can be linked to an external library.")
.def("make_function", &PythonMLIRModule::makeFunction,
"Defines a new mlir::FuncOp in the current mlir::Module.")
"Defines a new mlir::FuncOp in the current mlir::ModuleOp.")
.def("function_context", &PythonMLIRModule::makeFunctionContext,
"Defines a new mlir::FuncOp in the mlir::Module and creates the "
"Defines a new mlir::FuncOp in the mlir::ModuleOp and creates the "
"function context for building the body of the function.")
.def("get_function", &PythonMLIRModule::getNamedFunction,
"Looks up the function with the given name in the module.")
@ -806,7 +807,7 @@ PYBIND11_MODULE(pybind, m) {
.def("make_index_type", &PythonMLIRModule::makeIndexType,
"Returns an mlir::IndexType")
.def("compile", &PythonMLIRModule::compile,
"Compiles the mlir::Module to LLVMIR a creates new opaque "
"Compiles the mlir::ModuleOp to LLVMIR a creates new opaque "
"ExecutionEngine backed by the ORC JIT.")
.def("get_ir", &PythonMLIRModule::getIR,
"Returns a dump of the MLIR representation of the module. This is "

View File

@ -58,7 +58,7 @@ inline mlir::MemRefType floatMemRefType(mlir::MLIRContext *context,
}
/// A basic function builder
inline mlir::FuncOp makeFunction(mlir::Module module, llvm::StringRef name,
inline mlir::FuncOp makeFunction(mlir::ModuleOp module, llvm::StringRef name,
llvm::ArrayRef<mlir::Type> types,
llvm::ArrayRef<mlir::Type> resultTypes) {
auto *context = module.getContext();

View File

@ -28,7 +28,6 @@ class ConversionPattern;
class DialectConversion;
class MLIRContext;
class ModuleOp;
using Module = ModuleOp;
class RewritePattern;
class Type;
using OwningRewritePatternList = std::vector<std::unique_ptr<RewritePattern>>;
@ -52,7 +51,7 @@ void populateLinalg1ToLLVMConversionPatterns(
/// Convert the Linalg dialect types and RangeOp, ViewOp and SliceOp operations
/// to the LLVM IR dialect types and operations in the given `module`. This is
/// the main entry point to the conversion.
void convertToLLVM(mlir::Module module);
void convertToLLVM(mlir::ModuleOp module);
} // end namespace linalg
#endif // LINALG1_CONVERTTOLLVMDIALECT_H_

View File

@ -406,7 +406,7 @@ struct LinalgTypeConverter : public LLVMTypeConverter {
};
} // end anonymous namespace
void linalg::convertToLLVM(mlir::Module module) {
void linalg::convertToLLVM(mlir::ModuleOp module) {
// Remove affine constructs if any by using an existing pass.
PassManager pm;
pm.addPass(createLowerAffinePass());

View File

@ -34,7 +34,7 @@ using namespace linalg::intrinsics;
TEST_FUNC(linalg_ops) {
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
auto indexType = mlir::IndexType::get(&context);
mlir::FuncOp f = makeFunction(*module, "linalg_ops",
{indexType, indexType, indexType}, {});
@ -73,7 +73,7 @@ TEST_FUNC(linalg_ops) {
TEST_FUNC(linalg_ops_folded_slices) {
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
auto indexType = mlir::IndexType::get(&context);
mlir::FuncOp f = makeFunction(*module, "linalg_ops_folded_slices",
{indexType, indexType, indexType}, {});

View File

@ -37,7 +37,7 @@ using namespace linalg;
using namespace linalg::common;
using namespace linalg::intrinsics;
FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
FuncOp makeFunctionWithAMatmulOp(ModuleOp module, StringRef name) {
MLIRContext *context = module.getContext();
auto dynamic2DMemRefType = floatMemRefType<2>(context);
mlir::FuncOp f = linalg::common::makeFunction(
@ -66,7 +66,7 @@ FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
TEST_FUNC(foo) {
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_as_loops");
lowerToLoops(f);

View File

@ -34,7 +34,7 @@ using namespace linalg;
using namespace linalg::common;
using namespace linalg::intrinsics;
FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
FuncOp makeFunctionWithAMatmulOp(ModuleOp module, StringRef name) {
MLIRContext *context = module.getContext();
auto dynamic2DMemRefType = floatMemRefType<2>(context);
mlir::FuncOp f = linalg::common::makeFunction(
@ -63,7 +63,7 @@ FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
TEST_FUNC(matmul_as_matvec) {
MLIRContext context;
Module module = Module::create(UnknownLoc::get(&context));
ModuleOp module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(module, "matmul_as_matvec");
lowerToFinerGrainedTensorContraction(f);
composeSliceOps(f);
@ -81,7 +81,7 @@ TEST_FUNC(matmul_as_matvec) {
TEST_FUNC(matmul_as_dot) {
MLIRContext context;
Module module = Module::create(UnknownLoc::get(&context));
ModuleOp module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(module, "matmul_as_dot");
lowerToFinerGrainedTensorContraction(f);
lowerToFinerGrainedTensorContraction(f);
@ -102,7 +102,7 @@ TEST_FUNC(matmul_as_dot) {
TEST_FUNC(matmul_as_loops) {
MLIRContext context;
Module module = Module::create(UnknownLoc::get(&context));
ModuleOp module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(module, "matmul_as_loops");
lowerToLoops(f);
composeSliceOps(f);
@ -134,7 +134,7 @@ TEST_FUNC(matmul_as_loops) {
TEST_FUNC(matmul_as_matvec_as_loops) {
MLIRContext context;
Module module = Module::create(UnknownLoc::get(&context));
ModuleOp module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f =
makeFunctionWithAMatmulOp(module, "matmul_as_matvec_as_loops");
lowerToFinerGrainedTensorContraction(f);
@ -165,7 +165,7 @@ TEST_FUNC(matmul_as_matvec_as_loops) {
TEST_FUNC(matmul_as_matvec_as_affine) {
MLIRContext context;
Module module = Module::create(UnknownLoc::get(&context));
ModuleOp module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f =
makeFunctionWithAMatmulOp(module, "matmul_as_matvec_as_affine");
lowerToFinerGrainedTensorContraction(f);

View File

@ -37,7 +37,7 @@ using namespace linalg;
using namespace linalg::common;
using namespace linalg::intrinsics;
FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
FuncOp makeFunctionWithAMatmulOp(ModuleOp module, StringRef name) {
MLIRContext *context = module.getContext();
auto dynamic2DMemRefType = floatMemRefType<2>(context);
mlir::FuncOp f = linalg::common::makeFunction(
@ -109,7 +109,7 @@ TEST_FUNC(execution) {
// linalg.matmul operation and lower it all the way down to the LLVM IR
// dialect through partial conversions.
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_as_loops");
lowerToLoops(f);
convertLinalg3ToLLVM(*module);

View File

@ -20,11 +20,10 @@
namespace mlir {
class ModuleOp;
using Module = ModuleOp;
} // end namespace mlir
namespace linalg {
void convertLinalg3ToLLVM(mlir::Module module);
void convertLinalg3ToLLVM(mlir::ModuleOp module);
} // end namespace linalg
#endif // LINALG3_CONVERTTOLLVMDIALECT_H_

View File

@ -146,7 +146,7 @@ static void populateLinalg3ToLLVMConversionPatterns(
context);
}
void linalg::convertLinalg3ToLLVM(Module module) {
void linalg::convertLinalg3ToLLVM(ModuleOp module) {
// Remove affine constructs.
for (auto func : module.getOps<FuncOp>()) {
auto rr = lowerAffineConstructs(func);

View File

@ -34,7 +34,7 @@ using namespace linalg;
using namespace linalg::common;
using namespace linalg::intrinsics;
FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
FuncOp makeFunctionWithAMatmulOp(ModuleOp module, StringRef name) {
MLIRContext *context = module.getContext();
auto dynamic2DMemRefType = floatMemRefType<2>(context);
mlir::FuncOp f = linalg::common::makeFunction(
@ -64,7 +64,7 @@ FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
TEST_FUNC(matmul_tiled_loops) {
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_tiled_loops");
lowerToTiledLoops(f, {8, 9});
PassManager pm;
@ -95,7 +95,7 @@ TEST_FUNC(matmul_tiled_loops) {
TEST_FUNC(matmul_tiled_views) {
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_tiled_views");
OpBuilder b(f.getBody());
lowerToTiledViews(f, {b.create<ConstantIndexOp>(f.getLoc(), 8),
@ -124,7 +124,7 @@ TEST_FUNC(matmul_tiled_views) {
TEST_FUNC(matmul_tiled_views_as_loops) {
MLIRContext context;
OwningModuleRef module = Module::create(UnknownLoc::get(&context));
OwningModuleRef module = ModuleOp::create(UnknownLoc::get(&context));
mlir::FuncOp f =
makeFunctionWithAMatmulOp(*module, "matmul_tiled_views_as_loops");
OpBuilder b(f.getBody());

View File

@ -67,10 +67,10 @@ public:
/// Public API: convert the AST for a Toy module (source file) to an MLIR
/// Module.
mlir::Module mlirGen(ModuleAST &moduleAST) {
mlir::ModuleOp mlirGen(ModuleAST &moduleAST) {
// We create an empty MLIR module and codegen functions one at a time and
// add them to the module.
theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
theModule = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
for (FunctionAST &F : moduleAST) {
auto func = mlirGen(F);
@ -97,7 +97,7 @@ private:
mlir::MLIRContext &context;
/// A "module" matches a source file: it contains a list of functions.
mlir::Module theModule;
mlir::ModuleOp theModule;
/// The builder is a helper class to create IR inside a function. It is
/// re-initialized every time we enter a function and kept around as a

View File

@ -71,7 +71,7 @@ public:
mlir::OwningModuleRef mlirGen(ModuleAST &moduleAST) {
// We create an empty MLIR module and codegen functions one at a time and
// add them to the module.
theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
theModule = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
for (FunctionAST &F : moduleAST) {
auto func = mlirGen(F);

View File

@ -71,7 +71,7 @@ public:
mlir::OwningModuleRef mlirGen(ModuleAST &moduleAST) {
// We create an empty MLIR module and codegen functions one at a time and
// add them to the module.
theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
theModule = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
for (FunctionAST &F : moduleAST) {
auto func = mlirGen(F);

View File

@ -79,7 +79,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.ParseModule();
}
mlir::LogicalResult optimize(mlir::Module module) {
mlir::LogicalResult optimize(mlir::ModuleOp module) {
mlir::PassManager pm;
pm.addPass(mlir::createCanonicalizerPass());
pm.addPass(createShapeInferencePass());

View File

@ -205,7 +205,7 @@ private:
/// Return the prototype declaration for printf in the module, create it if
/// necessary.
FuncOp getPrintf(Module module) const {
FuncOp getPrintf(ModuleOp module) const {
auto printfFunc = module.getNamedFunction("printf");
if (printfFunc)
return printfFunc;

View File

@ -71,7 +71,7 @@ public:
mlir::OwningModuleRef mlirGen(ModuleAST &moduleAST) {
// We create an empty MLIR module and codegen functions one at a time and
// add them to the module.
theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
theModule = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
for (FunctionAST &F : moduleAST) {
auto func = mlirGen(F);

View File

@ -102,7 +102,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.ParseModule();
}
mlir::LogicalResult optimize(mlir::Module module) {
mlir::LogicalResult optimize(mlir::ModuleOp module) {
mlir::PassManager pm;
pm.addPass(mlir::createCanonicalizerPass());
pm.addPass(createShapeInferencePass());
@ -115,7 +115,7 @@ mlir::LogicalResult optimize(mlir::Module module) {
return pm.run(module);
}
mlir::LogicalResult lowerDialect(mlir::Module module, bool OnlyLinalg) {
mlir::LogicalResult lowerDialect(mlir::ModuleOp module, bool OnlyLinalg) {
mlir::PassManager pm;
pm.addPass(createEarlyLoweringPass());
pm.addPass(mlir::createCanonicalizerPass());

View File

@ -149,7 +149,7 @@ struct MyFunctionAnalysis {
/// An interesting module analysis.
struct MyModuleAnalysis {
// Compute this analysis with the provided module.
MyModuleAnalysis(Module module);
MyModuleAnalysis(ModuleOp module);
};
void MyFunctionPass::runOnFunction() {

View File

@ -31,7 +31,6 @@ class DialectConversion;
class LLVMTypeConverter;
class MLIRContext;
class ModuleOp;
using Module = ModuleOp;
class ModulePassBase;
class RewritePattern;
class Type;
@ -83,7 +82,7 @@ namespace LLVM {
/// support different values coming from the same predecessor. If a block has
/// another block as a successor more than once with different values, insert
/// a new dummy block for LLVM PHI nodes to tell the sources apart.
void ensureDistinctSuccessors(Module m);
void ensureDistinctSuccessors(ModuleOp m);
} // namespace LLVM
} // namespace mlir

View File

@ -37,7 +37,6 @@ class Module;
namespace mlir {
class ModuleOp;
using Module = ModuleOp;
namespace impl {
class OrcJIT;
@ -63,7 +62,8 @@ public:
/// If `sharedLibPaths` are provided, the underlying JIT-compilation will open
/// and link the shared libraries for symbol resolution.
static llvm::Expected<std::unique_ptr<ExecutionEngine>>
create(Module m, std::function<llvm::Error(llvm::Module *)> transformer = {},
create(ModuleOp m,
std::function<llvm::Error(llvm::Module *)> transformer = {},
ArrayRef<StringRef> sharedLibPaths = {});
/// Looks up a packed-argument function with the given name and returns a

View File

@ -26,7 +26,6 @@ namespace mlir {
class AffineExpr;
class BlockAndValueMapping;
class ModuleOp;
using Module = ModuleOp;
class UnknownLoc;
class FileLineColLoc;
class Type;
@ -58,7 +57,7 @@ class UnitAttr;
class Builder {
public:
explicit Builder(MLIRContext *context) : context(context) {}
explicit Builder(Module module);
explicit Builder(ModuleOp module);
MLIRContext *getContext() const { return context; }

View File

@ -198,10 +198,6 @@ private:
ModuleOp module;
};
/// Temporary forward declaration of ModuleOp as Module to support the legacy
/// naming.
using Module = ModuleOp;
} // end namespace mlir
namespace llvm {

View File

@ -31,31 +31,31 @@ class StringRef;
namespace mlir {
class Location;
class ModuleOp;
using Module = ModuleOp;
class MLIRContext;
class Type;
/// This parses the file specified by the indicated SourceMgr and returns an
/// MLIR module if it was valid. If not, the error message is emitted through
/// the error handler registered in the context, and a null pointer is returned.
Module parseSourceFile(const llvm::SourceMgr &sourceMgr, MLIRContext *context);
ModuleOp parseSourceFile(const llvm::SourceMgr &sourceMgr,
MLIRContext *context);
/// This parses the file specified by the indicated filename and returns an
/// MLIR module if it was valid. If not, the error message is emitted through
/// the error handler registered in the context, and a null pointer is returned.
Module parseSourceFile(llvm::StringRef filename, MLIRContext *context);
ModuleOp parseSourceFile(llvm::StringRef filename, MLIRContext *context);
/// This parses the file specified by the indicated filename using the provided
/// SourceMgr and returns an MLIR module if it was valid. If not, the error
/// message is emitted through the error handler registered in the context, and
/// a null pointer is returned.
Module parseSourceFile(llvm::StringRef filename, llvm::SourceMgr &sourceMgr,
MLIRContext *context);
ModuleOp parseSourceFile(llvm::StringRef filename, llvm::SourceMgr &sourceMgr,
MLIRContext *context);
/// This parses the module string to a MLIR module if it was valid. If not, the
/// error message is emitted through the error handler registered in the
/// context, and a null pointer is returned.
Module parseSourceString(llvm::StringRef moduleStr, MLIRContext *context);
ModuleOp parseSourceString(llvm::StringRef moduleStr, MLIRContext *context);
/// This parses a single MLIR type to an MLIR context if it was valid. If not,
/// an error message is emitted through a new SourceMgrDiagnosticHandler

View File

@ -223,7 +223,7 @@ private:
/// An analysis manager for a specific module instance.
class ModuleAnalysisManager {
public:
ModuleAnalysisManager(Module module, PassInstrumentor *passInstrumentor)
ModuleAnalysisManager(ModuleOp module, PassInstrumentor *passInstrumentor)
: moduleAnalyses(module), passInstrumentor(passInstrumentor) {}
ModuleAnalysisManager(const ModuleAnalysisManager &) = delete;
ModuleAnalysisManager &operator=(const ModuleAnalysisManager &) = delete;
@ -273,7 +273,7 @@ private:
functionAnalyses;
/// The analyses for the owning module.
detail::AnalysisMap<Module> moduleAnalyses;
detail::AnalysisMap<ModuleOp> moduleAnalyses;
/// An optional instrumentation object.
PassInstrumentor *passInstrumentor;

View File

@ -138,7 +138,8 @@ private:
/// Pass to transform a module. Derived passes should not inherit from this
/// class directly, and instead should use the CRTP ModulePass class.
class ModulePassBase : public Pass {
using PassStateT = detail::PassExecutionState<Module, ModuleAnalysisManager>;
using PassStateT =
detail::PassExecutionState<ModuleOp, ModuleAnalysisManager>;
public:
static bool classof(const Pass *pass) {
@ -152,7 +153,7 @@ protected:
virtual void runOnModule() = 0;
/// Return the current module being transformed.
Module getModule() { return getPassState().irAndPassFailed.getPointer(); }
ModuleOp getModule() { return getPassState().irAndPassFailed.getPointer(); }
/// Return the MLIR context for the current module being transformed.
MLIRContext &getContext() { return *getModule().getContext(); }
@ -171,7 +172,7 @@ protected:
private:
/// Forwarding function to execute this pass.
LLVM_NODISCARD
LogicalResult run(Module module, ModuleAnalysisManager &mam);
LogicalResult run(ModuleOp module, ModuleAnalysisManager &mam);
/// The current execution state for the pass.
llvm::Optional<PassStateT> passState;
@ -268,7 +269,7 @@ struct FunctionPass : public detail::PassModel<FuncOp, T, FunctionPassBase> {
/// Derived module passes are expected to provide the following:
/// - A 'void runOnModule()' method.
template <typename T>
struct ModulePass : public detail::PassModel<Module, T, ModulePassBase> {
struct ModulePass : public detail::PassModel<ModuleOp, T, ModulePassBase> {
/// Returns the analysis for a child function.
template <typename AnalysisT> AnalysisT &getFunctionAnalysis(FuncOp f) {
return this->getAnalysisManager().template getFunctionAnalysis<AnalysisT>(

View File

@ -28,7 +28,6 @@ class Any;
namespace mlir {
class FunctionPassBase;
class ModuleOp;
using Module = ModuleOp;
class ModulePassBase;
class Pass;
class PassInstrumentation;
@ -61,7 +60,7 @@ public:
/// Run the passes within this manager on the provided module.
LLVM_NODISCARD
LogicalResult run(Module module);
LogicalResult run(ModuleOp module);
/// Disable support for multi-threading within the pass manager.
void disableMultithreading(bool disable = true);

View File

@ -33,13 +33,12 @@ class Module;
namespace mlir {
class ModuleOp;
using Module = ModuleOp;
/// Convert the given MLIR module into LLVM IR. The LLVM context is extracted
/// from the registered LLVM IR dialect. In case of error, report it
/// to the error handler registered with the MLIR context, if any (obtained from
/// the MLIR module), and return `nullptr`.
std::unique_ptr<llvm::Module> translateModuleToLLVMIR(Module m);
std::unique_ptr<llvm::Module> translateModuleToLLVMIR(ModuleOp m);
} // namespace mlir

View File

@ -36,7 +36,6 @@ namespace mlir {
class Attribute;
class Location;
class ModuleOp;
using Module = ModuleOp;
class Operation;
namespace LLVM {
@ -49,7 +48,7 @@ namespace LLVM {
class ModuleTranslation {
public:
template <typename T = ModuleTranslation>
static std::unique_ptr<llvm::Module> translateModule(Module m) {
static std::unique_ptr<llvm::Module> translateModule(ModuleOp m) {
auto llvmModule = prepareLLVMModule(m);
T translator(m);
@ -64,14 +63,13 @@ protected:
// Translate the given MLIR module expressed in MLIR LLVM IR dialect into an
// LLVM IR module. The MLIR LLVM IR dialect holds a pointer to an
// LLVMContext, the LLVM IR module will be created in that context.
explicit ModuleTranslation(Module module) : mlirModule(module) {}
explicit ModuleTranslation(ModuleOp module) : mlirModule(module) {}
virtual ~ModuleTranslation() {}
virtual bool convertOperation(Operation &op, llvm::IRBuilder<> &builder);
static std::unique_ptr<llvm::Module> prepareLLVMModule(Module m);
static std::unique_ptr<llvm::Module> prepareLLVMModule(ModuleOp m);
private:
bool convertFunctions();
bool convertOneFunction(FuncOp func);
void connectPHINodes(FuncOp func);
@ -84,7 +82,7 @@ private:
Location loc);
// Original and translated module.
Module mlirModule;
ModuleOp mlirModule;
std::unique_ptr<llvm::Module> llvmModule;
protected:

View File

@ -31,14 +31,13 @@ class Module;
namespace mlir {
class ModuleOp;
using Module = ModuleOp;
/// Convert the given MLIR module into NVVM IR. This conversion requires the
/// registration of the LLVM IR dialect and will extract the LLVM context
/// from the registered LLVM IR dialect. In case of error, report it
/// to the error handler registered with the MLIR context, if any (obtained from
/// the MLIR module), and return `nullptr`.
std::unique_ptr<llvm::Module> translateModuleToNVVMIR(Module m);
std::unique_ptr<llvm::Module> translateModuleToNVVMIR(ModuleOp m);
} // namespace mlir

View File

@ -339,7 +339,7 @@ private:
/// conversion object. This function returns failure if a type conversion
/// failed.
LLVM_NODISCARD LogicalResult applyConversionPatterns(
Module module, ConversionTarget &target, TypeConverter &converter,
ModuleOp module, ConversionTarget &target, TypeConverter &converter,
OwningRewritePatternList &&patterns);
/// Convert the given functions with the provided conversion patterns. This

View File

@ -35,8 +35,6 @@ namespace mlir {
class AffineApplyOp;
class AffineForOp;
class Location;
class ModuleOp;
using Module = ModuleOp;
class OpBuilder;
/// Replaces all "deferencing" uses of oldMemRef with newMemRef while optionally

View File

@ -28,18 +28,17 @@ namespace mlir {
struct LogicalResult;
class MLIRContext;
class ModuleOp;
using Module = ModuleOp;
class OwningModuleRef;
/// Interface of the function that translates a file to MLIR. The
/// implementation should create a new MLIR Module in the given context and
/// implementation should create a new MLIR ModuleOp in the given context and
/// return a pointer to it, or a nullptr in case of any error.
using TranslateToMLIRFunction =
std::function<OwningModuleRef(llvm::StringRef, MLIRContext *)>;
/// Interface of the function that translates MLIR to a different format and
/// outputs the result to a file. It is allowed to modify the module.
using TranslateFromMLIRFunction =
std::function<LogicalResult(Module, llvm::StringRef)>;
std::function<LogicalResult(ModuleOp, llvm::StringRef)>;
/// Use Translate[To|From]MLIRRegistration as a global initialiser that
/// registers a function and associates it with name. This requires that a

View File

@ -139,7 +139,7 @@ LogicalResult
GpuKernelToCubinPass::translateGpuKernelToCubinAnnotation(FuncOp &function) {
Builder builder(function.getContext());
OwningModuleRef module = Module::create(function.getLoc());
OwningModuleRef module = ModuleOp::create(function.getLoc());
// TODO(herhut): Also handle called functions.
module->push_back(function.clone());

View File

@ -150,7 +150,7 @@ private:
// The types in comments give the actual types expected/returned but the API
// uses void pointers. This is fine as they have the same linkage in C.
void GpuLaunchFuncToCudaCallsPass::declareCudaFunctions(Location loc) {
Module module = getModule();
ModuleOp module = getModule();
Builder builder(module);
if (!module.getNamedFunction(cuModuleLoadName)) {
module.push_back(

View File

@ -937,7 +937,7 @@ static void ensureDistinctSuccessors(Block &bb) {
}
}
void mlir::LLVM::ensureDistinctSuccessors(Module m) {
void mlir::LLVM::ensureDistinctSuccessors(ModuleOp m) {
for (auto f : m.getOps<FuncOp>()) {
for (auto &bb : f.getBlocks()) {
::ensureDistinctSuccessors(bb);
@ -1029,7 +1029,7 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
if (!typeConverterMaker || !patternListFiller)
return signalPassFailure();
Module m = getModule();
ModuleOp m = getModule();
LLVM::ensureDistinctSuccessors(m);
std::unique_ptr<LLVMTypeConverter> typeConverter =

View File

@ -322,7 +322,7 @@ void packFunctionArguments(llvm::Module *module) {
ExecutionEngine::~ExecutionEngine() = default;
Expected<std::unique_ptr<ExecutionEngine>>
ExecutionEngine::create(Module m,
ExecutionEngine::create(ModuleOp m,
std::function<llvm::Error(llvm::Module *)> transformer,
ArrayRef<StringRef> sharedLibPaths) {
auto engine = llvm::make_unique<ExecutionEngine>();

View File

@ -26,7 +26,7 @@
#include "mlir/Support/Functional.h"
using namespace mlir;
Builder::Builder(Module module) : context(module.getContext()) {}
Builder::Builder(ModuleOp module) : context(module.getContext()) {}
Identifier Builder::getIdentifier(StringRef str) {
return Identifier::get(str, context);

View File

@ -3980,12 +3980,12 @@ ParseResult ModuleParser::parseModule(ModuleOp module) {
/// This parses the file specified by the indicated SourceMgr and returns an
/// MLIR module if it was valid. If not, it emits diagnostics and returns
/// null.
Module mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
ModuleOp mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
auto sourceBuf = sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID());
// This is the result module we are parsing into.
OwningModuleRef module(Module::create(FileLineColLoc::get(
OwningModuleRef module(ModuleOp::create(FileLineColLoc::get(
sourceBuf->getBufferIdentifier(), /*line=*/0, /*column=*/0, context)));
ParserState state(sourceMgr, context);
@ -4003,7 +4003,7 @@ Module mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
/// This parses the file specified by the indicated filename and returns an
/// MLIR module if it was valid. If not, the error message is emitted through
/// the error handler registered in the context, and a null pointer is returned.
Module mlir::parseSourceFile(StringRef filename, MLIRContext *context) {
ModuleOp mlir::parseSourceFile(StringRef filename, MLIRContext *context) {
llvm::SourceMgr sourceMgr;
return parseSourceFile(filename, sourceMgr, context);
}
@ -4012,8 +4012,8 @@ Module mlir::parseSourceFile(StringRef filename, MLIRContext *context) {
/// SourceMgr and returns an MLIR module if it was valid. If not, the error
/// message is emitted through the error handler registered in the context, and
/// a null pointer is returned.
Module mlir::parseSourceFile(StringRef filename, llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
ModuleOp mlir::parseSourceFile(StringRef filename, llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
if (sourceMgr.getNumBuffers() != 0) {
// TODO(b/136086478): Extend to support multiple buffers.
emitError(mlir::UnknownLoc::get(context),
@ -4034,7 +4034,7 @@ Module mlir::parseSourceFile(StringRef filename, llvm::SourceMgr &sourceMgr,
/// This parses the program string to a MLIR module if it was valid. If not,
/// it emits diagnostics and returns null.
Module mlir::parseSourceString(StringRef moduleStr, MLIRContext *context) {
ModuleOp mlir::parseSourceString(StringRef moduleStr, MLIRContext *context) {
auto memBuffer = MemoryBuffer::getMemBuffer(moduleStr);
if (!memBuffer)
return nullptr;

View File

@ -80,8 +80,8 @@ static void printIR(const llvm::Any &ir, bool printModuleScope,
}
// Print the given module.
assert(llvm::any_isa<Module>(ir) && "unexpected IR unit");
llvm::any_cast<Module>(ir).print(out);
assert(llvm::any_isa<ModuleOp>(ir) && "unexpected IR unit");
llvm::any_cast<ModuleOp>(ir).print(out);
}
/// Instrumentation hooks.

View File

@ -71,7 +71,7 @@ LogicalResult FunctionPassBase::run(FuncOp fn, FunctionAnalysisManager &fam) {
}
/// Forwarding function to execute this pass.
LogicalResult ModulePassBase::run(Module module, ModuleAnalysisManager &mam) {
LogicalResult ModulePassBase::run(ModuleOp module, ModuleAnalysisManager &mam) {
// Initialize the pass state.
passState.emplace(module, mam);
@ -120,7 +120,7 @@ LogicalResult detail::FunctionPassExecutor::run(FuncOp function,
}
/// Run all of the passes in this manager over the current module.
LogicalResult detail::ModulePassExecutor::run(Module module,
LogicalResult detail::ModulePassExecutor::run(ModuleOp module,
ModuleAnalysisManager &mam) {
// Run each of the held passes.
for (auto &pass : passes)
@ -256,7 +256,7 @@ PassManager::PassManager(bool verifyPasses)
PassManager::~PassManager() {}
/// Run the passes within this manager on the provided module.
LogicalResult PassManager::run(Module module) {
LogicalResult PassManager::run(ModuleOp module) {
ModuleAnalysisManager mam(module, instrumentor.get());
return mpe->run(module, mam);
}

View File

@ -76,7 +76,7 @@ public:
ModulePassExecutor &operator=(const ModulePassExecutor &) = delete;
/// Run the executor on the given module.
LogicalResult run(Module module, ModuleAnalysisManager &mam);
LogicalResult run(ModuleOp module, ModuleAnalysisManager &mam);
/// Add a pass to the current executor. This takes ownership over the provided
/// pass pointer.

View File

@ -34,7 +34,7 @@ using namespace mlir;
// Adds a one-block function named as `spirv_module` to `module` and returns the
// block. The created block will be terminated by `std.return`.
Block *createOneBlockFunction(Builder builder, Module module) {
Block *createOneBlockFunction(Builder builder, ModuleOp module) {
auto fnType = builder.getFunctionType(/*inputs=*/{}, /*results=*/{});
auto fn = FuncOp::create(builder.getUnknownLoc(), "spirv_module", fnType);
module.push_back(fn);
@ -80,7 +80,7 @@ OwningModuleRef deserializeModule(llvm::StringRef inputFilename,
// converted SPIR-V ModuleOp inside a MLIR module. This should be changed to
// return the SPIR-V ModuleOp directly after module and function are migrated
// to be general ops.
OwningModuleRef module(Module::create(
OwningModuleRef module(ModuleOp::create(
FileLineColLoc::get(inputFilename, /*line=*/0, /*column=*/0, context)));
Block *block = createOneBlockFunction(builder, module.get());
block->push_front(spirvModule->getOperation());

View File

@ -31,7 +31,7 @@
using namespace mlir;
LogicalResult serializeModule(Module module, StringRef outputFilename) {
LogicalResult serializeModule(ModuleOp module, StringRef outputFilename) {
if (!module)
return failure();
@ -73,6 +73,6 @@ LogicalResult serializeModule(Module module, StringRef outputFilename) {
static TranslateFromMLIRRegistration
registration("serialize-spirv",
[](Module module, StringRef outputFilename) {
[](ModuleOp module, StringRef outputFilename) {
return serializeModule(module, outputFilename);
});

View File

@ -38,7 +38,7 @@ using namespace mlir;
// Storage for the translation function wrappers that survive the parser.
static llvm::SmallVector<TranslateFunction, 16> wrapperStorage;
static LogicalResult printMLIROutput(Module module,
static LogicalResult printMLIROutput(ModuleOp module,
llvm::StringRef outputFilename) {
if (failed(verify(module)))
return failure();

View File

@ -31,12 +31,12 @@
using namespace mlir;
std::unique_ptr<llvm::Module> mlir::translateModuleToLLVMIR(Module m) {
std::unique_ptr<llvm::Module> mlir::translateModuleToLLVMIR(ModuleOp m) {
return LLVM::ModuleTranslation::translateModule<>(m);
}
static TranslateFromMLIRRegistration registration(
"mlir-to-llvmir", [](Module module, llvm::StringRef outputFilename) {
"mlir-to-llvmir", [](ModuleOp module, llvm::StringRef outputFilename) {
if (!module)
return failure();

View File

@ -47,7 +47,8 @@ static llvm::Value *createIntrinsicCall(llvm::IRBuilder<> &builder,
class ModuleTranslation : public LLVM::ModuleTranslation {
public:
explicit ModuleTranslation(Module module) : LLVM::ModuleTranslation(module) {}
explicit ModuleTranslation(ModuleOp module)
: LLVM::ModuleTranslation(module) {}
~ModuleTranslation() override {}
protected:
@ -61,7 +62,7 @@ protected:
};
} // namespace
std::unique_ptr<llvm::Module> mlir::translateModuleToNVVMIR(Module m) {
std::unique_ptr<llvm::Module> mlir::translateModuleToNVVMIR(ModuleOp m) {
ModuleTranslation translation(m);
auto llvmModule =
LLVM::ModuleTranslation::translateModule<ModuleTranslation>(m);
@ -90,7 +91,7 @@ std::unique_ptr<llvm::Module> mlir::translateModuleToNVVMIR(Module m) {
static TranslateFromMLIRRegistration
registration("mlir-to-nvvmir",
[](Module module, llvm::StringRef outputFilename) {
[](ModuleOp module, llvm::StringRef outputFilename) {
if (!module)
return failure();

View File

@ -404,7 +404,7 @@ bool ModuleTranslation::convertFunctions() {
return false;
}
std::unique_ptr<llvm::Module> ModuleTranslation::prepareLLVMModule(Module m) {
std::unique_ptr<llvm::Module> ModuleTranslation::prepareLLVMModule(ModuleOp m) {
auto *dialect = m.getContext()->getRegisteredDialect<LLVM::LLVMDialect>();
assert(dialect && "LLVM dialect must be registered");

View File

@ -1128,7 +1128,7 @@ auto ConversionTarget::getOpAction(OperationName op) const
/// conversion object. If conversion fails for specific functions, those
/// functions remains unmodified.
LogicalResult
mlir::applyConversionPatterns(Module module, ConversionTarget &target,
mlir::applyConversionPatterns(ModuleOp module, ConversionTarget &target,
TypeConverter &converter,
OwningRewritePatternList &&patterns) {
SmallVector<FuncOp, 32> allFunctions(module.getOps<FuncOp>());

View File

@ -557,7 +557,7 @@ TEST_FUNC(vectorize_2d) {
makeFunction("vectorize_2d", {}, {memrefType, memrefType, memrefType});
mlir::FuncOp f = owningF;
mlir::OwningModuleRef module = Module::create(&globalContext());
mlir::OwningModuleRef module = ModuleOp::create(&globalContext());
module->push_back(f);
OpBuilder builder(f.getBody());

View File

@ -152,7 +152,7 @@ static void printMemRefArguments(ArrayRef<Type> argTypes,
// - canonicalization
// - affine to standard lowering
// - standard to llvm lowering
static LogicalResult convertAffineStandardToLLVMIR(Module module) {
static LogicalResult convertAffineStandardToLLVMIR(ModuleOp module) {
PassManager manager;
manager.addPass(mlir::createCanonicalizerPass());
manager.addPass(mlir::createCSEPass());
@ -162,7 +162,7 @@ static LogicalResult convertAffineStandardToLLVMIR(Module module) {
}
static Error compileAndExecuteFunctionWithMemRefs(
Module module, StringRef entryPoint,
ModuleOp module, StringRef entryPoint,
std::function<llvm::Error(llvm::Module *)> transformer) {
FuncOp mainFunction = module.getNamedFunction(entryPoint);
if (!mainFunction || mainFunction.getBlocks().empty()) {
@ -205,7 +205,7 @@ static Error compileAndExecuteFunctionWithMemRefs(
}
static Error compileAndExecuteSingleFloatReturnFunction(
Module module, StringRef entryPoint,
ModuleOp module, StringRef entryPoint,
std::function<llvm::Error(llvm::Module *)> transformer) {
FuncOp mainFunction = module.getNamedFunction(entryPoint);
if (!mainFunction || mainFunction.isExternal()) {
@ -255,7 +255,7 @@ static Error compileAndExecuteSingleFloatReturnFunction(
// The latter is applied after parsing the input into MLIR IR and before passing
// the MLIR module to the ExecutionEngine.
int run(int argc, char **argv,
llvm::function_ref<LogicalResult(mlir::Module)> mlirTransformer) {
llvm::function_ref<LogicalResult(mlir::ModuleOp)> mlirTransformer) {
llvm::PrettyStackTraceProgram x(argc, argv);
llvm::InitLLVM y(argc, argv);

View File

@ -42,7 +42,7 @@ using namespace mlir;
// TODO(herhut) Factor out into an include file and proper library.
extern int run(int argc, char **argv,
llvm::function_ref<LogicalResult(Module)>);
llvm::function_ref<LogicalResult(ModuleOp)>);
inline void emit_cuda_error(const llvm::Twine &message, const char *buffer,
CUresult error, FuncOp &function) {
@ -126,7 +126,7 @@ public:
};
} // end anonymous namespace
static LogicalResult runMLIRPasses(Module m) {
static LogicalResult runMLIRPasses(ModuleOp m) {
// As we gradually lower, the IR is inconsistent between passes. So do not
// verify inbetween.
PassManager pm(/*verifyPasses=*/false);

View File

@ -26,18 +26,18 @@ namespace {
/// Minimal class definitions for two analyses.
struct MyAnalysis {
MyAnalysis(FuncOp) {}
MyAnalysis(Module) {}
MyAnalysis(ModuleOp) {}
};
struct OtherAnalysis {
OtherAnalysis(FuncOp) {}
OtherAnalysis(Module) {}
OtherAnalysis(ModuleOp) {}
};
TEST(AnalysisManagerTest, FineGrainModuleAnalysisPreservation) {
MLIRContext context;
// Test fine grain invalidation of the module analysis manager.
OwningModuleRef module(Module::create(UnknownLoc::get(&context)));
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
// Query two different analyses, but only preserve one before invalidating.
@ -58,7 +58,7 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
Builder builder(&context);
// Create a function and a module.
OwningModuleRef module(Module::create(UnknownLoc::get(&context)));
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
FuncOp func1 =
FuncOp::create(builder.getUnknownLoc(), "foo",
builder.getFunctionType(llvm::None, llvm::None));
@ -86,7 +86,7 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
Builder builder(&context);
// Create a function and a module.
OwningModuleRef module(Module::create(UnknownLoc::get(&context)));
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
FuncOp func1 =
FuncOp::create(builder.getUnknownLoc(), "foo",
builder.getFunctionType(llvm::None, llvm::None));