diff --git a/mlir/examples/toy/Ch2/include/toy/MLIRGen.h b/mlir/examples/toy/Ch2/include/toy/MLIRGen.h --- a/mlir/examples/toy/Ch2/include/toy/MLIRGen.h +++ b/mlir/examples/toy/Ch2/include/toy/MLIRGen.h @@ -18,7 +18,9 @@ namespace mlir { class MLIRContext; -class OwningModuleRef; +template +class OwningOpRef; +class ModuleOp; } // namespace mlir namespace toy { @@ -26,7 +28,8 @@ /// 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 mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST); } // namespace toy #endif // TOY_MLIRGEN_H diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp @@ -443,8 +443,8 @@ namespace toy { // The public API for codegen. -mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, - ModuleAST &moduleAST) { +mlir::OwningOpRef mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST) { return MLIRGenImpl(context).mlirGen(moduleAST); } diff --git a/mlir/examples/toy/Ch2/toyc.cpp b/mlir/examples/toy/Ch2/toyc.cpp --- a/mlir/examples/toy/Ch2/toyc.cpp +++ b/mlir/examples/toy/Ch2/toyc.cpp @@ -78,7 +78,7 @@ auto moduleAST = parseInputFile(inputFilename); if (!moduleAST) return 6; - mlir::OwningModuleRef module = mlirGen(context, *moduleAST); + mlir::OwningOpRef module = mlirGen(context, *moduleAST); if (!module) return 1; @@ -97,7 +97,8 @@ // Parse the input mlir. llvm::SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), llvm::SMLoc()); - mlir::OwningModuleRef module = mlir::parseSourceFile(sourceMgr, &context); + mlir::OwningOpRef module = + mlir::parseSourceFile(sourceMgr, &context); if (!module) { llvm::errs() << "Error can't load file " << inputFilename << "\n"; return 3; diff --git a/mlir/examples/toy/Ch3/include/toy/MLIRGen.h b/mlir/examples/toy/Ch3/include/toy/MLIRGen.h --- a/mlir/examples/toy/Ch3/include/toy/MLIRGen.h +++ b/mlir/examples/toy/Ch3/include/toy/MLIRGen.h @@ -18,7 +18,9 @@ namespace mlir { class MLIRContext; -class OwningModuleRef; +template +class OwningOpRef; +class ModuleOp; } // namespace mlir namespace toy { @@ -26,7 +28,8 @@ /// 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 mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST); } // namespace toy #endif // TOY_MLIRGEN_H diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp @@ -443,8 +443,8 @@ namespace toy { // The public API for codegen. -mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, - ModuleAST &moduleAST) { +mlir::OwningOpRef mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST) { return MLIRGenImpl(context).mlirGen(moduleAST); } diff --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp --- a/mlir/examples/toy/Ch3/toyc.cpp +++ b/mlir/examples/toy/Ch3/toyc.cpp @@ -72,7 +72,7 @@ } int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, - mlir::OwningModuleRef &module) { + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -106,7 +106,7 @@ // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); - mlir::OwningModuleRef module; + mlir::OwningOpRef module; llvm::SourceMgr sourceMgr; mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); if (int error = loadMLIR(sourceMgr, context, module)) diff --git a/mlir/examples/toy/Ch4/include/toy/MLIRGen.h b/mlir/examples/toy/Ch4/include/toy/MLIRGen.h --- a/mlir/examples/toy/Ch4/include/toy/MLIRGen.h +++ b/mlir/examples/toy/Ch4/include/toy/MLIRGen.h @@ -18,7 +18,9 @@ namespace mlir { class MLIRContext; -class OwningModuleRef; +template +class OwningOpRef; +class ModuleOp; } // namespace mlir namespace toy { @@ -26,7 +28,8 @@ /// 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 mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST); } // namespace toy #endif // TOY_MLIRGEN_H diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp @@ -447,8 +447,8 @@ namespace toy { // The public API for codegen. -mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, - ModuleAST &moduleAST) { +mlir::OwningOpRef mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST) { return MLIRGenImpl(context).mlirGen(moduleAST); } diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -73,7 +73,7 @@ } int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, - mlir::OwningModuleRef &module) { + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -107,7 +107,7 @@ // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); - mlir::OwningModuleRef module; + mlir::OwningOpRef module; llvm::SourceMgr sourceMgr; mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); if (int error = loadMLIR(sourceMgr, context, module)) diff --git a/mlir/examples/toy/Ch5/include/toy/MLIRGen.h b/mlir/examples/toy/Ch5/include/toy/MLIRGen.h --- a/mlir/examples/toy/Ch5/include/toy/MLIRGen.h +++ b/mlir/examples/toy/Ch5/include/toy/MLIRGen.h @@ -18,7 +18,9 @@ namespace mlir { class MLIRContext; -class OwningModuleRef; +template +class OwningOpRef; +class ModuleOp; } // namespace mlir namespace toy { @@ -26,7 +28,8 @@ /// 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 mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST); } // namespace toy #endif // TOY_MLIRGEN_H diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp @@ -447,8 +447,8 @@ namespace toy { // The public API for codegen. -mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, - ModuleAST &moduleAST) { +mlir::OwningOpRef mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST) { return MLIRGenImpl(context).mlirGen(moduleAST); } diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -77,7 +77,7 @@ } int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, - mlir::OwningModuleRef &module) { + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -111,7 +111,7 @@ // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); - mlir::OwningModuleRef module; + mlir::OwningOpRef module; llvm::SourceMgr sourceMgr; mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); if (int error = loadMLIR(sourceMgr, context, module)) diff --git a/mlir/examples/toy/Ch6/include/toy/MLIRGen.h b/mlir/examples/toy/Ch6/include/toy/MLIRGen.h --- a/mlir/examples/toy/Ch6/include/toy/MLIRGen.h +++ b/mlir/examples/toy/Ch6/include/toy/MLIRGen.h @@ -18,7 +18,9 @@ namespace mlir { class MLIRContext; -class OwningModuleRef; +template +class OwningOpRef; +class ModuleOp; } // namespace mlir namespace toy { @@ -26,7 +28,8 @@ /// 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 mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST); } // namespace toy #endif // TOY_MLIRGEN_H diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp @@ -447,8 +447,8 @@ namespace toy { // The public API for codegen. -mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, - ModuleAST &moduleAST) { +mlir::OwningOpRef mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST) { return MLIRGenImpl(context).mlirGen(moduleAST); } diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -96,7 +96,8 @@ return parser.parseModule(); } -int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { +int loadMLIR(mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -127,7 +128,7 @@ } int loadAndProcessMLIR(mlir::MLIRContext &context, - mlir::OwningModuleRef &module) { + mlir::OwningOpRef &module) { if (int error = loadMLIR(context, module)) return error; @@ -267,7 +268,7 @@ // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); - mlir::OwningModuleRef module; + mlir::OwningOpRef module; if (int error = loadAndProcessMLIR(context, module)) return error; diff --git a/mlir/examples/toy/Ch7/include/toy/MLIRGen.h b/mlir/examples/toy/Ch7/include/toy/MLIRGen.h --- a/mlir/examples/toy/Ch7/include/toy/MLIRGen.h +++ b/mlir/examples/toy/Ch7/include/toy/MLIRGen.h @@ -18,7 +18,9 @@ namespace mlir { class MLIRContext; -class OwningModuleRef; +template +class OwningOpRef; +class ModuleOp; } // namespace mlir namespace toy { @@ -26,7 +28,8 @@ /// 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 mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST); } // namespace toy #endif // TOY_MLIRGEN_H diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp --- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp @@ -669,8 +669,8 @@ namespace toy { // The public API for codegen. -mlir::OwningModuleRef mlirGen(mlir::MLIRContext &context, - ModuleAST &moduleAST) { +mlir::OwningOpRef mlirGen(mlir::MLIRContext &context, + ModuleAST &moduleAST) { return MLIRGenImpl(context).mlirGen(moduleAST); } diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -96,7 +96,8 @@ return parser.parseModule(); } -int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { +int loadMLIR(mlir::MLIRContext &context, + mlir::OwningOpRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -127,7 +128,7 @@ } int loadAndProcessMLIR(mlir::MLIRContext &context, - mlir::OwningModuleRef &module) { + mlir::OwningOpRef &module) { if (int error = loadMLIR(context, module)) return error; @@ -268,7 +269,7 @@ // Load our Dialect in this MLIR Context. context.getOrLoadDialect(); - mlir::OwningModuleRef module; + mlir::OwningOpRef module; if (int error = loadAndProcessMLIR(context, module)) return error; diff --git a/mlir/include/mlir/IR/BuiltinOps.h b/mlir/include/mlir/IR/BuiltinOps.h --- a/mlir/include/mlir/IR/BuiltinOps.h +++ b/mlir/include/mlir/IR/BuiltinOps.h @@ -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 { -public: - using OwningOpRef::OwningOpRef; - OwningModuleRef() = default; - OwningModuleRef(OwningOpRef &&other) - : OwningOpRef(std::move(other)) {} -}; -} // namespace mlir - namespace llvm { /// Allow stealing the low bits of FuncOp. template <> diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -612,7 +612,7 @@ PDLPatternModule() = default; /// Construct a PDL pattern with the given module. - PDLPatternModule(OwningModuleRef pdlModule) + PDLPatternModule(OwningOpRef pdlModule) : pdlModule(std::move(pdlModule)) {} /// Merge the state in `other` into this pattern module. @@ -669,7 +669,7 @@ private: /// The module containing the `pdl.pattern` operations. - OwningModuleRef pdlModule; + OwningOpRef pdlModule; /// The external functions referenced from within the PDL module. llvm::StringMap constraintFunctions; diff --git a/mlir/include/mlir/Parser.h b/mlir/include/mlir/Parser.h --- a/mlir/include/mlir/Parser.h +++ b/mlir/include/mlir/Parser.h @@ -206,21 +206,21 @@ /// 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 parseSourceFile(const llvm::SourceMgr &sourceMgr, + MLIRContext *context) { return parseSourceFile(sourceMgr, context); } -inline OwningModuleRef parseSourceFile(llvm::StringRef filename, - MLIRContext *context) { +inline OwningOpRef parseSourceFile(llvm::StringRef filename, + MLIRContext *context) { return parseSourceFile(filename, context); } -inline OwningModuleRef parseSourceFile(llvm::StringRef filename, - llvm::SourceMgr &sourceMgr, - MLIRContext *context) { +inline OwningOpRef parseSourceFile(llvm::StringRef filename, + llvm::SourceMgr &sourceMgr, + MLIRContext *context) { return parseSourceFile(filename, sourceMgr, context); } -inline OwningModuleRef parseSourceString(llvm::StringRef moduleStr, - MLIRContext *context) { +inline OwningOpRef parseSourceString(llvm::StringRef moduleStr, + MLIRContext *context) { return parseSourceString(moduleStr, context); } diff --git a/mlir/include/mlir/Target/LLVMIR/Import.h b/mlir/include/mlir/Target/LLVMIR/Import.h --- a/mlir/include/mlir/Target/LLVMIR/Import.h +++ b/mlir/include/mlir/Target/LLVMIR/Import.h @@ -25,14 +25,14 @@ 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 translateLLVMIRToModule(std::unique_ptr llvmModule, MLIRContext *context); diff --git a/mlir/include/mlir/Translation.h b/mlir/include/mlir/Translation.h --- a/mlir/include/mlir/Translation.h +++ b/mlir/include/mlir/Translation.h @@ -25,21 +25,22 @@ struct LogicalResult; class MLIRContext; class ModuleOp; -class OwningModuleRef; +template +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; +using TranslateSourceMgrToMLIRFunction = std::function( + 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; + std::function(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. diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -177,7 +177,8 @@ } MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module) { - OwningModuleRef owning = parseSourceString(unwrap(module), unwrap(context)); + OwningOpRef owning = + parseSourceString(unwrap(module), unwrap(context)); if (!owning) return MlirModule{nullptr}; return MlirModule{owning.release().getOperation()}; @@ -192,8 +193,9 @@ } void mlirModuleDestroy(MlirModule module) { - // Transfer ownership to an OwningModuleRef so that its destructor is called. - OwningModuleRef(unwrap(module)); + // Transfer ownership to an OwningOpRef so that its destructor is + // called. + OwningOpRef(unwrap(module)); } MlirOperation mlirModuleGetOperation(MlirModule module) { diff --git a/mlir/lib/ExecutionEngine/JitRunner.cpp b/mlir/lib/ExecutionEngine/JitRunner.cpp --- a/mlir/lib/ExecutionEngine/JitRunner.cpp +++ b/mlir/lib/ExecutionEngine/JitRunner.cpp @@ -110,8 +110,8 @@ } // namespace -static OwningModuleRef parseMLIRInput(StringRef inputFilename, - MLIRContext *context) { +static OwningOpRef parseMLIRInput(StringRef inputFilename, + MLIRContext *context) { // Set up the input file. std::string errorMessage; auto file = openInputFile(inputFilename, &errorMessage); @@ -122,7 +122,7 @@ llvm::SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(std::move(file), SMLoc()); - return OwningModuleRef(parseSourceFile(sourceMgr, context)); + return OwningOpRef(parseSourceFile(sourceMgr, context)); } static inline Error makeStringError(const Twine &message) { diff --git a/mlir/lib/Support/MlirOptMain.cpp b/mlir/lib/Support/MlirOptMain.cpp --- a/mlir/lib/Support/MlirOptMain.cpp +++ b/mlir/lib/Support/MlirOptMain.cpp @@ -59,7 +59,7 @@ // Parse the input file and reset the context threading state. TimingScope parserTiming = timing.nest("Parser"); - OwningModuleRef module(parseSourceFile(sourceMgr, context)); + OwningOpRef module(parseSourceFile(sourceMgr, context)); context->enableMultithreading(wasThreadingEnabled); if (!module) return failure(); diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -854,11 +854,11 @@ return success(); } -OwningModuleRef +OwningOpRef mlir::translateLLVMIRToModule(std::unique_ptr llvmModule, MLIRContext *context) { context->loadDialect(); - OwningModuleRef module(ModuleOp::create( + OwningOpRef module(ModuleOp::create( FileLineColLoc::get(context, "", /*line=*/0, /*column=*/0))); Importer deserializer(context, module.get()); @@ -876,8 +876,8 @@ // Deserializes the LLVM bitcode stored in `input` into an MLIR module in the // LLVM dialect. -OwningModuleRef translateLLVMIRToModule(llvm::SourceMgr &sourceMgr, - MLIRContext *context) { +OwningOpRef translateLLVMIRToModule(llvm::SourceMgr &sourceMgr, + MLIRContext *context) { llvm::SMDiagnostic err; llvm::LLVMContext llvmContext; std::unique_ptr llvmModule = llvm::parseIR( diff --git a/mlir/lib/Target/SPIRV/TranslateRegistration.cpp b/mlir/lib/Target/SPIRV/TranslateRegistration.cpp --- a/mlir/lib/Target/SPIRV/TranslateRegistration.cpp +++ b/mlir/lib/Target/SPIRV/TranslateRegistration.cpp @@ -35,8 +35,8 @@ // 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 deserializeModule(const llvm::MemoryBuffer *input, + MLIRContext *context) { context->loadDialect(); // Make sure the input stream can be treated as a stream of SPIR-V words @@ -56,7 +56,7 @@ if (!spirvModule) return {}; - OwningModuleRef module(ModuleOp::create(FileLineColLoc::get( + OwningOpRef module(ModuleOp::create(FileLineColLoc::get( context, input->getBufferIdentifier(), /*line=*/0, /*column=*/0))); module->getBody()->push_front(spirvModule.release()); @@ -147,7 +147,7 @@ return failure(); // Wrap around in a new MLIR module. - OwningModuleRef dstModule(ModuleOp::create( + OwningOpRef dstModule(ModuleOp::create( FileLineColLoc::get(&deserializationContext, /*filename=*/"", /*line=*/0, /*column=*/0))); dstModule->getBody()->push_front(spirvModule.release()); diff --git a/mlir/lib/Translation/Translation.cpp b/mlir/lib/Translation/Translation.cpp --- a/mlir/lib/Translation/Translation.cpp +++ b/mlir/lib/Translation/Translation.cpp @@ -62,7 +62,7 @@ StringRef name, const TranslateSourceMgrToMLIRFunction &function) { auto wrappedFn = [function](llvm::SourceMgr &sourceMgr, raw_ostream &output, MLIRContext *context) { - OwningModuleRef module = function(sourceMgr, context); + OwningOpRef module = function(sourceMgr, context); if (!module || failed(verify(*module))) return failure(); module->print(output); @@ -101,7 +101,7 @@ DialectRegistry registry; dialectRegistration(registry); context->appendDialectRegistry(registry); - auto module = OwningModuleRef(parseSourceFile(sourceMgr, context)); + auto module = OwningOpRef(parseSourceFile(sourceMgr, context)); if (!module || failed(verify(*module))) return failure(); return function(module.get(), output); diff --git a/mlir/unittests/ExecutionEngine/Invoke.cpp b/mlir/unittests/ExecutionEngine/Invoke.cpp --- a/mlir/unittests/ExecutionEngine/Invoke.cpp +++ b/mlir/unittests/ExecutionEngine/Invoke.cpp @@ -63,7 +63,7 @@ registerAllDialects(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); - OwningModuleRef module = parseSourceString(moduleStr, &context); + OwningOpRef module = parseSourceString(moduleStr, &context); ASSERT_TRUE(!!module); ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module))); auto jitOrError = ExecutionEngine::create(*module); @@ -88,7 +88,7 @@ registerAllDialects(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); - OwningModuleRef module = parseSourceString(moduleStr, &context); + OwningOpRef module = parseSourceString(moduleStr, &context); ASSERT_TRUE(!!module); ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module))); auto jitOrError = ExecutionEngine::create(*module); @@ -207,7 +207,7 @@ registerAllDialects(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); - OwningModuleRef module = parseSourceString(moduleStr, &context); + OwningOpRef module = parseSourceString(moduleStr, &context); ASSERT_TRUE(!!module); ASSERT_TRUE(succeeded(lowerToLLVMDialect(*module))); auto jitOrError = ExecutionEngine::create(*module); diff --git a/mlir/unittests/Interfaces/ControlFlowInterfacesTest.cpp b/mlir/unittests/Interfaces/ControlFlowInterfacesTest.cpp --- a/mlir/unittests/Interfaces/ControlFlowInterfacesTest.cpp +++ b/mlir/unittests/Interfaces/ControlFlowInterfacesTest.cpp @@ -83,7 +83,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef 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 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef 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 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); Operation *testOp = &module->getBody()->getOperations().front(); Operation *op1 = &testOp->getRegion(0).front().front().getRegion(0).front().front(); diff --git a/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp b/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp --- a/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp +++ b/mlir/unittests/Interfaces/DataLayoutInterfacesTest.cpp @@ -236,7 +236,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef 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 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); @@ -280,7 +280,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); @@ -306,7 +306,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); @@ -338,7 +338,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); @@ -369,7 +369,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); @@ -395,7 +395,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); @@ -414,7 +414,7 @@ registry.insert(); MLIRContext ctx(registry); - OwningModuleRef module = parseSourceString(ir, &ctx); + OwningOpRef module = parseSourceString(ir, &ctx); auto op = cast(module->getBody()->getOperations().front()); DataLayout layout(op); diff --git a/mlir/unittests/Interfaces/InferTypeOpInterfaceTest.cpp b/mlir/unittests/Interfaces/InferTypeOpInterfaceTest.cpp --- a/mlir/unittests/Interfaces/InferTypeOpInterfaceTest.cpp +++ b/mlir/unittests/Interfaces/InferTypeOpInterfaceTest.cpp @@ -47,7 +47,7 @@ DialectRegistry registry; MLIRContext ctx; - OwningModuleRef module; + OwningOpRef module; FuncOp mapFn; }; diff --git a/mlir/unittests/Pass/AnalysisManagerTest.cpp b/mlir/unittests/Pass/AnalysisManagerTest.cpp --- a/mlir/unittests/Pass/AnalysisManagerTest.cpp +++ b/mlir/unittests/Pass/AnalysisManagerTest.cpp @@ -32,7 +32,7 @@ MLIRContext context; // Test fine grain invalidation of the module analysis manager. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr); AnalysisManager am = mam; @@ -54,7 +54,7 @@ Builder builder(&context); // Create a function and a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); FuncOp func1 = FuncOp::create(builder.getUnknownLoc(), "foo", builder.getFunctionType(llvm::None, llvm::None)); @@ -84,7 +84,7 @@ Builder builder(&context); // Create a function and a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); FuncOp func1 = FuncOp::create(builder.getUnknownLoc(), "foo", builder.getFunctionType(llvm::None, llvm::None)); @@ -128,7 +128,7 @@ Builder builder(&context); // Create a function and a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr); AnalysisManager am = mam; @@ -150,7 +150,7 @@ MLIRContext context; // Create a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr); AnalysisManager am = mam; @@ -174,7 +174,7 @@ MLIRContext context; // Create a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr); AnalysisManager am = mam; @@ -205,7 +205,7 @@ MLIRContext context; // Create a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr); AnalysisManager am = mam; @@ -237,7 +237,7 @@ MLIRContext context; // Create a module. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr); AnalysisManager am = mam; diff --git a/mlir/unittests/Pass/PassManagerTest.cpp b/mlir/unittests/Pass/PassManagerTest.cpp --- a/mlir/unittests/Pass/PassManagerTest.cpp +++ b/mlir/unittests/Pass/PassManagerTest.cpp @@ -50,7 +50,7 @@ Builder builder(&context); // Create a module with 2 functions. - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); for (StringRef name : {"secret", "not_secret"}) { FuncOp func = FuncOp::create(builder.getUnknownLoc(), name, @@ -95,7 +95,7 @@ context.allowUnregisteredDialects(); // Create a module - OwningModuleRef module(ModuleOp::create(UnknownLoc::get(&context))); + OwningOpRef module(ModuleOp::create(UnknownLoc::get(&context))); // Add a single "invalid_op" operation OpBuilder builder(&module->getBodyRegion()); diff --git a/mlir/unittests/Transforms/Canonicalizer.cpp b/mlir/unittests/Transforms/Canonicalizer.cpp --- a/mlir/unittests/Transforms/Canonicalizer.cpp +++ b/mlir/unittests/Transforms/Canonicalizer.cpp @@ -74,7 +74,7 @@ %1 = "test.foo"() {sym_name = "B"} : () -> (f32) )mlir"; - OwningModuleRef module = mlir::parseSourceString(code, &context); + OwningOpRef module = mlir::parseSourceString(code, &context); ASSERT_TRUE(succeeded(mgr.run(*module))); EXPECT_TRUE(module->lookupSymbol("B"));