Replace OwningModuleRef with OwningOpRef<ModuleOp>

This addresses a TODO in BuiltinOps.h.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D118574
This commit is contained in:
Sanjoy Das 2022-01-29 18:41:10 -08:00
parent 73fd7d2304
commit 8f66ab1c2e
36 changed files with 122 additions and 115 deletions

View File

@ -18,7 +18,9 @@
namespace mlir {
class MLIRContext;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
class ModuleOp;
} // namespace mlir
namespace toy {
@ -26,7 +28,8 @@ class ModuleAST;
/// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
/// or nullptr on failure.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST);
} // namespace toy
#endif // TOY_MLIRGEN_H

View File

@ -443,8 +443,8 @@ private:
namespace toy {
// The public API for codegen.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
return MLIRGenImpl(context).mlirGen(moduleAST);
}

View File

@ -78,7 +78,7 @@ int dumpMLIR() {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
mlir::OwningModuleRef module = mlirGen(context, *moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> module = mlirGen(context, *moduleAST);
if (!module)
return 1;
@ -97,7 +97,8 @@ int dumpMLIR() {
// Parse the input mlir.
llvm::SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), llvm::SMLoc());
mlir::OwningModuleRef module = mlir::parseSourceFile(sourceMgr, &context);
mlir::OwningOpRef<mlir::ModuleOp> module =
mlir::parseSourceFile(sourceMgr, &context);
if (!module) {
llvm::errs() << "Error can't load file " << inputFilename << "\n";
return 3;

View File

@ -18,7 +18,9 @@
namespace mlir {
class MLIRContext;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
class ModuleOp;
} // namespace mlir
namespace toy {
@ -26,7 +28,8 @@ class ModuleAST;
/// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
/// or nullptr on failure.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST);
} // namespace toy
#endif // TOY_MLIRGEN_H

View File

@ -443,8 +443,8 @@ private:
namespace toy {
// The public API for codegen.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
return MLIRGenImpl(context).mlirGen(moduleAST);
}

View File

@ -72,7 +72,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
}
int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningModuleRef &module) {
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
@ -106,7 +106,7 @@ int dumpMLIR() {
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();
mlir::OwningModuleRef module;
mlir::OwningOpRef<mlir::ModuleOp> module;
llvm::SourceMgr sourceMgr;
mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context);
if (int error = loadMLIR(sourceMgr, context, module))

View File

@ -18,7 +18,9 @@
namespace mlir {
class MLIRContext;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
class ModuleOp;
} // namespace mlir
namespace toy {
@ -26,7 +28,8 @@ class ModuleAST;
/// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
/// or nullptr on failure.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST);
} // namespace toy
#endif // TOY_MLIRGEN_H

View File

@ -447,8 +447,8 @@ private:
namespace toy {
// The public API for codegen.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
return MLIRGenImpl(context).mlirGen(moduleAST);
}

View File

@ -73,7 +73,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
}
int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningModuleRef &module) {
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
@ -107,7 +107,7 @@ int dumpMLIR() {
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();
mlir::OwningModuleRef module;
mlir::OwningOpRef<mlir::ModuleOp> module;
llvm::SourceMgr sourceMgr;
mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context);
if (int error = loadMLIR(sourceMgr, context, module))

View File

@ -18,7 +18,9 @@
namespace mlir {
class MLIRContext;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
class ModuleOp;
} // namespace mlir
namespace toy {
@ -26,7 +28,8 @@ class ModuleAST;
/// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
/// or nullptr on failure.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST);
} // namespace toy
#endif // TOY_MLIRGEN_H

View File

@ -447,8 +447,8 @@ private:
namespace toy {
// The public API for codegen.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
return MLIRGenImpl(context).mlirGen(moduleAST);
}

View File

@ -77,7 +77,7 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
}
int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
mlir::OwningModuleRef &module) {
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
@ -111,7 +111,7 @@ int dumpMLIR() {
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();
mlir::OwningModuleRef module;
mlir::OwningOpRef<mlir::ModuleOp> module;
llvm::SourceMgr sourceMgr;
mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context);
if (int error = loadMLIR(sourceMgr, context, module))

View File

@ -18,7 +18,9 @@
namespace mlir {
class MLIRContext;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
class ModuleOp;
} // namespace mlir
namespace toy {
@ -26,7 +28,8 @@ class ModuleAST;
/// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
/// or nullptr on failure.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST);
} // namespace toy
#endif // TOY_MLIRGEN_H

View File

@ -447,8 +447,8 @@ private:
namespace toy {
// The public API for codegen.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
return MLIRGenImpl(context).mlirGen(moduleAST);
}

View File

@ -96,7 +96,8 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule();
}
int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) {
int loadMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
@ -127,7 +128,7 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) {
}
int loadAndProcessMLIR(mlir::MLIRContext &context,
mlir::OwningModuleRef &module) {
mlir::OwningOpRef<mlir::ModuleOp> &module) {
if (int error = loadMLIR(context, module))
return error;
@ -267,7 +268,7 @@ int main(int argc, char **argv) {
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();
mlir::OwningModuleRef module;
mlir::OwningOpRef<mlir::ModuleOp> module;
if (int error = loadAndProcessMLIR(context, module))
return error;

View File

@ -18,7 +18,9 @@
namespace mlir {
class MLIRContext;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
class ModuleOp;
} // namespace mlir
namespace toy {
@ -26,7 +28,8 @@ class ModuleAST;
/// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
/// or nullptr on failure.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST);
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST);
} // namespace toy
#endif // TOY_MLIRGEN_H

View File

@ -669,8 +669,8 @@ private:
namespace toy {
// The public API for codegen.
mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
ModuleAST &moduleAST) {
return MLIRGenImpl(context).mlirGen(moduleAST);
}

View File

@ -96,7 +96,8 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) {
return parser.parseModule();
}
int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) {
int loadMLIR(mlir::MLIRContext &context,
mlir::OwningOpRef<mlir::ModuleOp> &module) {
// Handle '.toy' input to the compiler.
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
@ -127,7 +128,7 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) {
}
int loadAndProcessMLIR(mlir::MLIRContext &context,
mlir::OwningModuleRef &module) {
mlir::OwningOpRef<mlir::ModuleOp> &module) {
if (int error = loadMLIR(context, module))
return error;
@ -268,7 +269,7 @@ int main(int argc, char **argv) {
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::toy::ToyDialect>();
mlir::OwningModuleRef module;
mlir::OwningOpRef<mlir::ModuleOp> module;
if (int error = loadAndProcessMLIR(context, module))
return error;

View File

@ -31,23 +31,6 @@
#define GET_OP_CLASSES
#include "mlir/IR/BuiltinOps.h.inc"
//===----------------------------------------------------------------------===//
// Dialect Utilities
//===----------------------------------------------------------------------===//
namespace mlir {
/// This class acts as an owning reference to a module, and will automatically
/// destroy the held module on destruction if the held module is valid.
// TODO: Remove this class in favor of using OwningOpRef directly.
class OwningModuleRef : public OwningOpRef<ModuleOp> {
public:
using OwningOpRef<ModuleOp>::OwningOpRef;
OwningModuleRef() = default;
OwningModuleRef(OwningOpRef<ModuleOp> &&other)
: OwningOpRef<ModuleOp>(std::move(other)) {}
};
} // namespace mlir
namespace llvm {
/// Allow stealing the low bits of FuncOp.
template <>

View File

@ -612,7 +612,7 @@ public:
PDLPatternModule() = default;
/// Construct a PDL pattern with the given module.
PDLPatternModule(OwningModuleRef pdlModule)
PDLPatternModule(OwningOpRef<ModuleOp> pdlModule)
: pdlModule(std::move(pdlModule)) {}
/// Merge the state in `other` into this pattern module.
@ -669,7 +669,7 @@ public:
private:
/// The module containing the `pdl.pattern` operations.
OwningModuleRef pdlModule;
OwningOpRef<ModuleOp> pdlModule;
/// The external functions referenced from within the PDL module.
llvm::StringMap<PDLConstraintFunction> constraintFunctions;

View File

@ -206,21 +206,21 @@ inline OwningOpRef<ContainerOpT> parseSourceString(llvm::StringRef sourceStr,
/// TODO: These methods are deprecated in favor of the above template versions.
/// They should be removed when usages have been updated.
inline OwningModuleRef parseSourceFile(const llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
inline OwningOpRef<ModuleOp> parseSourceFile(const llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
return parseSourceFile<ModuleOp>(sourceMgr, context);
}
inline OwningModuleRef parseSourceFile(llvm::StringRef filename,
MLIRContext *context) {
inline OwningOpRef<ModuleOp> parseSourceFile(llvm::StringRef filename,
MLIRContext *context) {
return parseSourceFile<ModuleOp>(filename, context);
}
inline OwningModuleRef parseSourceFile(llvm::StringRef filename,
llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
inline OwningOpRef<ModuleOp> parseSourceFile(llvm::StringRef filename,
llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
return parseSourceFile<ModuleOp>(filename, sourceMgr, context);
}
inline OwningModuleRef parseSourceString(llvm::StringRef moduleStr,
MLIRContext *context) {
inline OwningOpRef<ModuleOp> parseSourceString(llvm::StringRef moduleStr,
MLIRContext *context) {
return parseSourceString<ModuleOp>(moduleStr, context);
}

View File

@ -25,14 +25,14 @@ class Module;
namespace mlir {
class DialectRegistry;
class OwningModuleRef;
class MLIRContext;
/// Convert the given LLVM module into MLIR's LLVM dialect. 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 `{}`.
OwningModuleRef
OwningOpRef<ModuleOp>
translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
MLIRContext *context);

View File

@ -25,21 +25,22 @@ class DialectRegistry;
struct LogicalResult;
class MLIRContext;
class ModuleOp;
class OwningModuleRef;
template <typename OpTy>
class OwningOpRef;
/// Interface of the function that translates the sources managed by `sourceMgr`
/// to MLIR. The source manager has at least one buffer. The 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 TranslateSourceMgrToMLIRFunction =
std::function<OwningModuleRef(llvm::SourceMgr &sourceMgr, MLIRContext *)>;
using TranslateSourceMgrToMLIRFunction = std::function<OwningOpRef<ModuleOp>(
llvm::SourceMgr &sourceMgr, MLIRContext *)>;
/// Interface of the function that translates the given string to MLIR. The
/// implementation should create a new MLIR ModuleOp in the given context. If
/// source-related error reporting is required from within the function, use
/// TranslateSourceMgrToMLIRFunction instead.
using TranslateStringRefToMLIRFunction =
std::function<OwningModuleRef(llvm::StringRef, MLIRContext *)>;
std::function<OwningOpRef<ModuleOp>(llvm::StringRef, MLIRContext *)>;
/// Interface of the function that translates MLIR to a different format and
/// outputs the result to a stream. It is allowed to modify the module.

View File

@ -177,7 +177,8 @@ MlirModule mlirModuleCreateEmpty(MlirLocation location) {
}
MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module) {
OwningModuleRef owning = parseSourceString(unwrap(module), unwrap(context));
OwningOpRef<ModuleOp> owning =
parseSourceString(unwrap(module), unwrap(context));
if (!owning)
return MlirModule{nullptr};
return MlirModule{owning.release().getOperation()};
@ -192,8 +193,9 @@ MlirBlock mlirModuleGetBody(MlirModule module) {
}
void mlirModuleDestroy(MlirModule module) {
// Transfer ownership to an OwningModuleRef so that its destructor is called.
OwningModuleRef(unwrap(module));
// Transfer ownership to an OwningOpRef<ModuleOp> so that its destructor is
// called.
OwningOpRef<ModuleOp>(unwrap(module));
}
MlirOperation mlirModuleGetOperation(MlirModule module) {

View File

@ -110,8 +110,8 @@ struct CompileAndExecuteConfig {
} // namespace
static OwningModuleRef parseMLIRInput(StringRef inputFilename,
MLIRContext *context) {
static OwningOpRef<ModuleOp> parseMLIRInput(StringRef inputFilename,
MLIRContext *context) {
// Set up the input file.
std::string errorMessage;
auto file = openInputFile(inputFilename, &errorMessage);
@ -122,7 +122,7 @@ static OwningModuleRef parseMLIRInput(StringRef inputFilename,
llvm::SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(file), SMLoc());
return OwningModuleRef(parseSourceFile(sourceMgr, context));
return OwningOpRef<ModuleOp>(parseSourceFile(sourceMgr, context));
}
static inline Error makeStringError(const Twine &message) {

View File

@ -59,7 +59,7 @@ static LogicalResult performActions(raw_ostream &os, bool verifyDiagnostics,
// Parse the input file and reset the context threading state.
TimingScope parserTiming = timing.nest("Parser");
OwningModuleRef module(parseSourceFile(sourceMgr, context));
OwningOpRef<ModuleOp> module(parseSourceFile(sourceMgr, context));
context->enableMultithreading(wasThreadingEnabled);
if (!module)
return failure();

View File

@ -854,11 +854,11 @@ LogicalResult Importer::processBasicBlock(llvm::BasicBlock *bb, Block *block) {
return success();
}
OwningModuleRef
OwningOpRef<ModuleOp>
mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
MLIRContext *context) {
context->loadDialect<LLVMDialect>();
OwningModuleRef module(ModuleOp::create(
OwningOpRef<ModuleOp> module(ModuleOp::create(
FileLineColLoc::get(context, "", /*line=*/0, /*column=*/0)));
Importer deserializer(context, module.get());
@ -876,8 +876,8 @@ mlir::translateLLVMIRToModule(std::unique_ptr<llvm::Module> llvmModule,
// Deserializes the LLVM bitcode stored in `input` into an MLIR module in the
// LLVM dialect.
OwningModuleRef translateLLVMIRToModule(llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
OwningOpRef<ModuleOp> translateLLVMIRToModule(llvm::SourceMgr &sourceMgr,
MLIRContext *context) {
llvm::SMDiagnostic err;
llvm::LLVMContext llvmContext;
std::unique_ptr<llvm::Module> llvmModule = llvm::parseIR(

View File

@ -35,8 +35,8 @@ using namespace mlir;
// Deserializes the SPIR-V binary module stored in the file named as
// `inputFilename` and returns a module containing the SPIR-V module.
static OwningModuleRef deserializeModule(const llvm::MemoryBuffer *input,
MLIRContext *context) {
static OwningOpRef<ModuleOp> deserializeModule(const llvm::MemoryBuffer *input,
MLIRContext *context) {
context->loadDialect<spirv::SPIRVDialect>();
// Make sure the input stream can be treated as a stream of SPIR-V words
@ -56,7 +56,7 @@ static OwningModuleRef deserializeModule(const llvm::MemoryBuffer *input,
if (!spirvModule)
return {};
OwningModuleRef module(ModuleOp::create(FileLineColLoc::get(
OwningOpRef<ModuleOp> module(ModuleOp::create(FileLineColLoc::get(
context, input->getBufferIdentifier(), /*line=*/0, /*column=*/0)));
module->getBody()->push_front(spirvModule.release());
@ -147,7 +147,7 @@ static LogicalResult roundTripModule(ModuleOp srcModule, bool emitDebugInfo,
return failure();
// Wrap around in a new MLIR module.
OwningModuleRef dstModule(ModuleOp::create(
OwningOpRef<ModuleOp> dstModule(ModuleOp::create(
FileLineColLoc::get(&deserializationContext,
/*filename=*/"", /*line=*/0, /*column=*/0)));
dstModule->getBody()->push_front(spirvModule.release());

View File

@ -62,7 +62,7 @@ static void registerTranslateToMLIRFunction(
StringRef name, const TranslateSourceMgrToMLIRFunction &function) {
auto wrappedFn = [function](llvm::SourceMgr &sourceMgr, raw_ostream &output,
MLIRContext *context) {
OwningModuleRef module = function(sourceMgr, context);
OwningOpRef<ModuleOp> module = function(sourceMgr, context);
if (!module || failed(verify(*module)))
return failure();
module->print(output);
@ -101,7 +101,7 @@ TranslateFromMLIRRegistration::TranslateFromMLIRRegistration(
DialectRegistry registry;
dialectRegistration(registry);
context->appendDialectRegistry(registry);
auto module = OwningModuleRef(parseSourceFile(sourceMgr, context));
auto module = OwningOpRef<ModuleOp>(parseSourceFile(sourceMgr, context));
if (!module || failed(verify(*module)))
return failure();
return function(module.get(), output);

View File

@ -63,7 +63,7 @@ TEST(MLIRExecutionEngine, AddInteger) {
registerAllDialects(registry);
registerLLVMDialectTranslation(registry);
MLIRContext context(registry);
OwningModuleRef module = parseSourceString(moduleStr, &context);
OwningOpRef<ModuleOp> module = parseSourceString(moduleStr, &context);
ASSERT_TRUE(!!module);
ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module)));
auto jitOrError = ExecutionEngine::create(*module);
@ -88,7 +88,7 @@ TEST(MLIRExecutionEngine, SubtractFloat) {
registerAllDialects(registry);
registerLLVMDialectTranslation(registry);
MLIRContext context(registry);
OwningModuleRef module = parseSourceString(moduleStr, &context);
OwningOpRef<ModuleOp> module = parseSourceString(moduleStr, &context);
ASSERT_TRUE(!!module);
ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module)));
auto jitOrError = ExecutionEngine::create(*module);
@ -207,7 +207,7 @@ TEST(NativeMemRefJit, BasicMemref) {
registerAllDialects(registry);
registerLLVMDialectTranslation(registry);
MLIRContext context(registry);
OwningModuleRef module = parseSourceString(moduleStr, &context);
OwningOpRef<ModuleOp> module = parseSourceString(moduleStr, &context);
ASSERT_TRUE(!!module);
ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module)));
auto jitOrError = ExecutionEngine::create(*module);

View File

@ -83,7 +83,7 @@ TEST(RegionBranchOpInterface, MutuallyExclusiveOps) {
registry.insert<CFTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
Operation *testOp = &module->getBody()->getOperations().front();
Operation *op1 = &testOp->getRegion(0).front().front();
Operation *op2 = &testOp->getRegion(1).front().front();
@ -104,7 +104,7 @@ TEST(RegionBranchOpInterface, NotMutuallyExclusiveOps) {
registry.insert<CFTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
Operation *testOp = &module->getBody()->getOperations().front();
Operation *op1 = &testOp->getRegion(0).front().front();
Operation *op2 = &testOp->getRegion(1).front().front();
@ -131,7 +131,7 @@ TEST(RegionBranchOpInterface, NestedMutuallyExclusiveOps) {
registry.insert<CFTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
Operation *testOp = &module->getBody()->getOperations().front();
Operation *op1 =
&testOp->getRegion(0).front().front().getRegion(0).front().front();

View File

@ -236,7 +236,7 @@ module {}
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
DataLayout layout(module.get());
EXPECT_EQ(layout.getTypeSize(IntegerType::get(&ctx, 42)), 6u);
EXPECT_EQ(layout.getTypeSize(Float16Type::get(&ctx)), 2u);
@ -257,7 +257,7 @@ TEST(DataLayout, NullSpec) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);
@ -280,7 +280,7 @@ TEST(DataLayout, EmptySpec) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);
@ -306,7 +306,7 @@ TEST(DataLayout, SpecWithEntries) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);
@ -338,7 +338,7 @@ TEST(DataLayout, Caching) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);
@ -369,7 +369,7 @@ TEST(DataLayout, CacheInvalidation) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);
@ -395,7 +395,7 @@ TEST(DataLayout, UnimplementedTypeInterface) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);
@ -414,7 +414,7 @@ TEST(DataLayout, SevenBitByte) {
registry.insert<DLTIDialect, DLTestDialect>();
MLIRContext ctx(registry);
OwningModuleRef module = parseSourceString(ir, &ctx);
OwningOpRef<ModuleOp> module = parseSourceString(ir, &ctx);
auto op =
cast<DataLayoutOpInterface>(module->getBody()->getOperations().front());
DataLayout layout(op);

View File

@ -47,7 +47,7 @@ protected:
DialectRegistry registry;
MLIRContext ctx;
OwningModuleRef module;
OwningOpRef<ModuleOp> module;
FuncOp mapFn;
};

View File

@ -32,7 +32,7 @@ TEST(AnalysisManagerTest, FineGrainModuleAnalysisPreservation) {
MLIRContext context;
// Test fine grain invalidation of the module analysis manager.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
AnalysisManager am = mam;
@ -54,7 +54,7 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
Builder builder(&context);
// Create a function and a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
FuncOp func1 =
FuncOp::create(builder.getUnknownLoc(), "foo",
builder.getFunctionType(llvm::None, llvm::None));
@ -84,7 +84,7 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
Builder builder(&context);
// Create a function and a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
FuncOp func1 =
FuncOp::create(builder.getUnknownLoc(), "foo",
builder.getFunctionType(llvm::None, llvm::None));
@ -128,7 +128,7 @@ TEST(AnalysisManagerTest, CustomInvalidation) {
Builder builder(&context);
// Create a function and a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
AnalysisManager am = mam;
@ -150,7 +150,7 @@ TEST(AnalysisManagerTest, OpSpecificAnalysis) {
MLIRContext context;
// Create a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
AnalysisManager am = mam;
@ -174,7 +174,7 @@ TEST(AnalysisManagerTest, DependentAnalysis) {
MLIRContext context;
// Create a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
AnalysisManager am = mam;
@ -205,7 +205,7 @@ TEST(AnalysisManagerTest, NestedDependentAnalysis) {
MLIRContext context;
// Create a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
AnalysisManager am = mam;
@ -237,7 +237,7 @@ TEST(AnalysisManagerTest, DependentAnalysis2Ctors) {
MLIRContext context;
// Create a module.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
AnalysisManager am = mam;

View File

@ -50,7 +50,7 @@ TEST(PassManagerTest, OpSpecificAnalysis) {
Builder builder(&context);
// Create a module with 2 functions.
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
for (StringRef name : {"secret", "not_secret"}) {
FuncOp func =
FuncOp::create(builder.getUnknownLoc(), name,
@ -95,7 +95,7 @@ TEST(PassManagerTest, InvalidPass) {
context.allowUnregisteredDialects();
// Create a module
OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context)));
OwningOpRef<ModuleOp> module(ModuleOp::create(UnknownLoc::get(&context)));
// Add a single "invalid_op" operation
OpBuilder builder(&module->getBodyRegion());

View File

@ -74,7 +74,7 @@ TEST(CanonicalizerTest, TestDisablePatterns) {
%1 = "test.foo"() {sym_name = "B"} : () -> (f32)
)mlir";
OwningModuleRef module = mlir::parseSourceString(code, &context);
OwningOpRef<ModuleOp> module = mlir::parseSourceString(code, &context);
ASSERT_TRUE(succeeded(mgr.run(*module)));
EXPECT_TRUE(module->lookupSymbol("B"));