NFC: Refactor Module to be value typed.

As with Functions, Module will soon become an operation, which are value-typed. This eases the transition from Module to ModuleOp. A new class, OwningModuleRef is provided to allow for owning a reference to a Module, and will auto-delete the held module on destruction.

PiperOrigin-RevId: 256196193
This commit is contained in:
River Riddle
2019-07-02 10:49:17 -07:00
committed by Mehdi Amini
parent b4a2dbc8b6
commit 206e55cc16
70 changed files with 373 additions and 283 deletions

View File

@@ -146,8 +146,8 @@ struct PythonFunction {
/// Trivial C++ wrappers make use of the EDSC C API.
struct PythonMLIRModule {
PythonMLIRModule()
: mlirContext(), module(new mlir::Module(&mlirContext)),
moduleManager(module.get()) {}
: mlirContext(), module(mlir::Module::create(&mlirContext)),
moduleManager(*module) {}
PythonType makeScalarType(const std::string &mlirElemType,
unsigned bitwidth) {
@@ -197,12 +197,12 @@ struct PythonMLIRModule {
manager.addPass(mlir::createCSEPass());
manager.addPass(mlir::createLowerAffinePass());
manager.addPass(mlir::createConvertToLLVMIRPass());
if (failed(manager.run(module.get()))) {
if (failed(manager.run(*module))) {
llvm::errs() << "conversion to the LLVM IR dialect failed\n";
return;
}
auto created = mlir::ExecutionEngine::create(module.get());
auto created = mlir::ExecutionEngine::create(*module);
llvm::handleAllErrors(created.takeError(),
[](const llvm::ErrorInfoBase &b) {
b.log(llvm::errs());
@@ -235,7 +235,7 @@ struct PythonMLIRModule {
private:
mlir::MLIRContext mlirContext;
// One single module in a python-exposed MLIRContext for now.
std::unique_ptr<mlir::Module> module;
mlir::OwningModuleRef module;
mlir::ModuleManager moduleManager;
std::unique_ptr<mlir::ExecutionEngine> engine;
};